Compare commits
870 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6766b14415 | |||
| 9d0f9e967f | |||
| d7609088e5 | |||
| b2643b6926 | |||
| 07b65ca069 | |||
| 25727f7f99 | |||
| 880ae89307 | |||
| 1496df1989 | |||
| 7d8ae6b4b1 | |||
| 312d4cccaf | |||
| ce5f9f95ea | |||
| d9bf8a76d9 | |||
| f7a35fb9fe | |||
| 3ba691ded5 | |||
| 7a7277d56f | |||
| 76be5dd1d3 | |||
| 53dc63f3bc | |||
| 80da0bc9d5 | |||
| bce7af4e11 | |||
| 9da09b51ed | |||
| 86392f197f | |||
| 1c13046297 | |||
| fbc756b531 | |||
| 6c64b06453 | |||
| 241834029a | |||
| 5b8a9c0b47 | |||
| 037c29d24a | |||
| 893f26ac9a | |||
| d43f8e3100 | |||
| 2b42acf7b8 | |||
| f65b80ed42 | |||
| e84abbdc82 | |||
| 66269eabe9 | |||
| 36c0928483 | |||
| 9237e15adc | |||
| 0d3a2072b2 | |||
| aa2ee5dfc2 | |||
| b515fa39ec | |||
| 76e3f4eb92 | |||
| 4959e5c6c2 | |||
| 7082594bbc | |||
| 36dd35f238 | |||
| 9c9fb6a485 | |||
| 5438a4837b | |||
| 84996e8cb6 | |||
| 87a368a857 | |||
| 21412d93dd | |||
| 0b11ff22b4 | |||
| 8fafa78796 | |||
| c43158f8a2 | |||
| 92ad524947 | |||
| b362a61863 | |||
| 468fec38d7 | |||
| 89830a5ae0 | |||
| 5977c296bd | |||
| 47d5792d97 | |||
| 25d706a913 | |||
| 048236aaaa | |||
| d442c58fd1 | |||
| f890f6bb09 | |||
| 036d466790 | |||
| dee47ba2d8 | |||
| be96c28b77 | |||
| ad1c0f578e | |||
| c8f7b1b72c | |||
| c89702ae84 | |||
| 2d29a82250 | |||
| b36c65e654 | |||
| 09b072b908 | |||
| 0ae9fee350 | |||
| 1579182ed9 | |||
| 074671aa71 | |||
| 36b7c47247 | |||
| 424d5b3025 | |||
| 8a5d352733 | |||
| f383629282 | |||
| a6d717cb04 | |||
| 84a5753301 | |||
| 5d2d9c7e81 | |||
| 82801d1411 | |||
| 340c3963d8 | |||
| ef15cf9847 | |||
| 4d613ccfa7 | |||
| 43ce34d547 | |||
| eda074cd80 | |||
| a2396d82f6 | |||
| a38721db93 | |||
| a06e811717 | |||
| 86e534ff75 | |||
| 640d5b2dec | |||
| 57e9b27085 | |||
| c56eefc739 | |||
| cf28306997 | |||
| 10acf3ddd1 | |||
| fed3ed9f9a | |||
| 260138ba11 | |||
| 67f7e0089c | |||
| d4a22c7851 | |||
| 06cf986490 | |||
| adf9aa04ce | |||
| 69f66fbe52 | |||
| d061005c89 | |||
| f6ee8b9f04 | |||
| 31af22c2ff | |||
| c421e3f243 | |||
| 6e92902407 | |||
| 6256381dc3 | |||
| b247b051ea | |||
| afbd553622 | |||
| 36bc14e884 | |||
| 9c5d0ff2ff | |||
| cfa6c8ddf6 | |||
| 21924bf022 | |||
| eea33f6019 | |||
| 66d48ae808 | |||
| de9b9fd0b1 | |||
| ece7384be4 | |||
| 0c052e4506 | |||
| 1996a0a3d6 | |||
| 679ad9b8c6 | |||
| d4983731e7 | |||
| 4fec3c8f34 | |||
| 836fd2565f | |||
| 54618064a1 | |||
| 519e3e01ae | |||
| aec8f81358 | |||
| c1d6bf4366 | |||
| 9bf2b79d9e | |||
| 4d98408995 | |||
| 7b466388f9 | |||
| b926fb3c66 | |||
| 6c8d5c0d0e | |||
| 5a1d234260 | |||
| fd6d42c297 | |||
| 7310ad6e92 | |||
| 7e47b1348d | |||
| 1e3555a6b7 | |||
| 9a67ce5968 | |||
| 279d7955f8 | |||
| db977c0bf5 | |||
| ba6bc59818 | |||
| 6e8be0578c | |||
| 92f7d16b5e | |||
| 40bb3c2f5e | |||
| 56a6096221 | |||
| ee37b42a91 | |||
| 0806e61df4 | |||
| 279ffeeefa | |||
| 80c5ee2479 | |||
| 16208544e5 | |||
| 6afeb24fdb | |||
| e6357b81eb | |||
| dfc2efe8a6 | |||
| f28b96f431 | |||
| a10293f8f7 | |||
| b1f02f91d7 | |||
| e76fa45d86 | |||
| 06f43892a5 | |||
| a094332b0d | |||
| 7b8779f534 | |||
| 371bf20d19 | |||
| 0f633ddd15 | |||
| 7886ca7f5f | |||
| 9b4c11954d | |||
| a1b724f30a | |||
| 7c3b2fb9cc | |||
| acef68d67e | |||
| 7e393d5f1e | |||
| 955c31b165 | |||
| e307cd48ad | |||
| 25f8b9e451 | |||
| e8ba14a2c1 | |||
| 9670d3341c | |||
| cec9778fd5 | |||
| 7451db4a68 | |||
| e31777ec53 | |||
| 7aa0b3dc7a | |||
| e7b2d5dc01 | |||
| 47d728667d | |||
| e1f8989d54 | |||
| 1d8cb47830 | |||
| faaa7c37a9 | |||
| 0aff9d8df4 | |||
| 30c3f8c1ac | |||
| bcd2469e01 | |||
| 983c6ae73d | |||
| 6d8e1fe776 | |||
| 99b4921309 | |||
| 3c231c3c9e | |||
| 175c0a6236 | |||
| 0031ceb06c | |||
| e3cc5a63df | |||
| 3cb61402c2 | |||
| 5336c51199 | |||
| 52aa658aaa | |||
| d08a51d7e4 | |||
| d97a557ac3 | |||
| 8a68d9cded | |||
| b031f7e902 | |||
| 963ffecb96 | |||
| 8f8aaca818 | |||
| 801f92b7e7 | |||
| 44db45700e | |||
| 25902005f6 | |||
| ffec71e0d8 | |||
| 99a208110b | |||
| e56799c993 | |||
| 957eb300f8 | |||
| 626025d539 | |||
| 9e8a0a020f | |||
| 40f592eade | |||
| 5e899f0be4 | |||
| f2748284b1 | |||
| a15ce00934 | |||
| 9e3e80261b | |||
| c72c685434 | |||
| 0177a8d277 | |||
| b6a9b0a4c9 | |||
| f4f8bd8d42 | |||
| 6e4aeffc0c | |||
| dba256d384 | |||
| 910008e9e7 | |||
| 8cb9545c41 | |||
| 59c16da6fb | |||
| 630df5bbd2 | |||
| f550111400 | |||
| 77377195aa | |||
| 7e2e72bd40 | |||
| aa7a13bd02 | |||
| 5895058a17 | |||
| ffb60d5149 | |||
| 1e2cb279b0 | |||
| e7f766f5ba | |||
| 8de5aa9409 | |||
| bf28a4df49 | |||
| fe1a0ab371 | |||
| 01daccfaf7 | |||
| 94e861e298 | |||
| d36af2ed5c | |||
| 7104b33214 | |||
| 32998e5377 | |||
| af0c9ef092 | |||
| 3bc3b3d10e | |||
| f03f42ca4d | |||
| 79783abeb1 | |||
| 895b0bd602 | |||
| 2ee5ee92f8 | |||
| 3e619423b1 | |||
| b524e18bdf | |||
| 6aa4579db8 | |||
| 17fb86c0f1 | |||
| 62ecfe4873 | |||
| 04e55e6b9a | |||
| f432aa1090 | |||
| 7add104313 | |||
| 36de249066 | |||
| b7a54dcffd | |||
| 6bb28deab2 | |||
| 7f88d15c86 | |||
| 94c5014e23 | |||
| c5a8256500 | |||
| 5f39884bf7 | |||
| d96825a242 | |||
| 443a938091 | |||
| 6bc3197721 | |||
| 269cc91fd5 | |||
| c1ddea479d | |||
| 5f3a95962c | |||
| ee1a8e6a32 | |||
| eeae73296e | |||
| 4ca8357af4 | |||
| 8a5b8c87fb | |||
| 6ab04d7bbc | |||
| a5a1380636 | |||
| eeab1aef64 | |||
| 4e1c342e55 | |||
| d8ed259bce | |||
| 9f6cb5de4c | |||
| ba634118d7 | |||
| 63da091d36 | |||
| ad0dc88a33 | |||
| 147acf4b57 | |||
| 5085f3a15e | |||
| 22a95ad8ea | |||
| df4bd6a60c | |||
| 813e7b05e4 | |||
| ab8b486b4a | |||
| 590f666ec9 | |||
| 9adaee915b | |||
| bce0f06fe9 | |||
| 856ecb84a0 | |||
| 90ddc06c98 | |||
| 405abc4e95 | |||
| 549c59ecf5 | |||
| 0a485eafcb | |||
| e0c11956a6 | |||
| da6a9bf3eb | |||
| dacd11e1cc | |||
| fc854b4c77 | |||
| 4dcc1f0374 | |||
| fc57390242 | |||
| bd15ef0a0c | |||
| 967ecafc33 | |||
| 29576da985 | |||
| 200a2556ef | |||
| ae0ab5025e | |||
| aa74276b25 | |||
| b03112a5dd | |||
| a3f49df62d | |||
| aa2af3f6dd | |||
| 20dcbc593c | |||
| 472ba8c1fd | |||
| d8345a44a4 | |||
| a187cb6c9c | |||
| b89c0b35d1 | |||
| 7ffcc0a5e7 | |||
| bde43fbdfb | |||
| 3728b2208f | |||
| dc52a756ee | |||
| 98dc886841 | |||
| d0cf104e43 | |||
| d7ed2412f6 | |||
| 7d38f0e234 | |||
| 3e8d072d24 | |||
| 84ac771893 | |||
| 3a9e0b5be6 | |||
| 9694ff433f | |||
| 2e82e78b98 | |||
| aaef4bee27 | |||
| 4ca8569488 | |||
| 8377ada3e0 | |||
| 8a034d59ed | |||
| 8e492d8798 | |||
| 7974ef80d7 | |||
| 3664d86430 | |||
| 9adef80d6b | |||
| be57adaee7 | |||
| d117e442a4 | |||
| 8820bc0796 | |||
| 57a64de023 | |||
| 5ed689ceb0 | |||
| 25f1765f36 | |||
| 063bd58802 | |||
| 901c6b34fa | |||
| 5b2d6488a2 | |||
| f6f35415d1 | |||
| 6c6069e963 | |||
| 6219d82560 | |||
| 1dcd7a16ab | |||
| b60caeb9dd | |||
| 4c4768aaf3 | |||
| 2f4ac0a663 | |||
| 23a446f852 | |||
| ec48334a1a | |||
| f4c061d412 | |||
| 31a076d7b3 | |||
| 6bd43d986c | |||
| dd32a2f15a | |||
| c88c20820f | |||
| 86de510731 | |||
| 0b31fbf827 | |||
| 34ad1450eb | |||
| e6ba71390d | |||
| f0c8dbe0ec | |||
| bf046a8ccb | |||
| b05ba7683e | |||
| aedf8dad15 | |||
| 74ebb7c722 | |||
| 1307f66494 | |||
| 448a24cb36 | |||
| 7266f23450 | |||
| c0ad31acfc | |||
| 25d3a0de27 | |||
| 1e38bbfbc1 | |||
| 1c62e95812 | |||
| d453cc27a3 | |||
| 2c3e841d8a | |||
| 50668c462f | |||
| 8d1192e832 | |||
| 4a8e2e9ed4 | |||
| 12fc45220a | |||
| 6bce68fbe7 | |||
| d54f947c98 | |||
| 6c8bb3a22e | |||
| ed29ce5183 | |||
| a51d269b7c | |||
| 8283e4e6d6 | |||
| 23ce91eb55 | |||
| 545ac7fcfa | |||
| 3926ccccad | |||
| f431307ef2 | |||
| ca368e0f9b | |||
| 8afeb56c11 | |||
| 2a6f90c5f3 | |||
| 271031128e | |||
| b991f954d0 | |||
| f12bb3f80d | |||
| 6dc978e8d8 | |||
| 9f05a873bc | |||
| 703d498772 | |||
| ed3b9543bb | |||
| fc7efba7d8 | |||
| b3178fe8f4 | |||
| e36798a993 | |||
| a143605465 | |||
| d3ad35b21e | |||
| 68134941bf | |||
| 54d0fef559 | |||
| 7f9c47176a | |||
| 9060ac7897 | |||
| d9073e4a17 | |||
| de1c1d7cc2 | |||
| 6ff1bd5917 | |||
| a6b04f426e | |||
| fa49dbe2cb | |||
| 682eb04a52 | |||
| 77064fb09e | |||
| be8d93563a | |||
| d4a6a5216d | |||
| 1cb1427050 | |||
| e4f4eace1c | |||
| 30a98b7e8c | |||
| d36c8d95ad | |||
| 506bd0abcf | |||
| 8dd810c41d | |||
| d9d0dc5201 | |||
| 72880d9e03 | |||
| 6c7ec6eb1b | |||
| 705fc5d116 | |||
| d20b575b9b | |||
| c949beab9c | |||
| 3fb857c435 | |||
| 0a4f999ade | |||
| f0b7147881 | |||
| b36a42cd0a | |||
| 000309b47f | |||
| 5cb12988f0 | |||
| 50c4b749ec | |||
| 5db2734e6f | |||
| e9e5507483 | |||
| d63dc7adfb | |||
| 27db44a8db | |||
| 1a035e2866 | |||
| 887aa20116 | |||
| 5e03d86695 | |||
| 95075aa28e | |||
| 0260f0790a | |||
| 34d65ba292 | |||
| 27a77a15ed | |||
| 76025bfae1 | |||
| 4957faf482 | |||
| 0d8e16d5c8 | |||
| 07baed1581 | |||
| eab5da075a | |||
| 0d1bbb19ce | |||
| 58d6cbc6ac | |||
| 4d3b627839 | |||
| 49455c99ad | |||
| 31bb6bedbd | |||
| 8d54678ea1 | |||
| 590767c299 | |||
| ec1bd342b8 | |||
| b031c9e7f6 | |||
| ea0dfe83b7 | |||
| bdd90f2c57 | |||
| 288dac5d70 | |||
| 9d22e1c35e | |||
| ace2359e7b | |||
| 617e6510a5 | |||
| 26024770b8 | |||
| d556f58e34 | |||
| b6f302dfc0 | |||
| 8e9b5f14af | |||
| 3635c00143 | |||
| abc71baaa6 | |||
| 959aaebede | |||
| d17f8c5049 | |||
| 42a7201a70 | |||
| 1f1744a49a | |||
| fd7dbe5bd9 | |||
| 984549400d | |||
| cf0c49277e | |||
| 16c3f9fa9c | |||
| 2f2539cf34 | |||
| e66823d017 | |||
| 881c32a3df | |||
| ea0a361c35 | |||
| dc60f8bb7b | |||
| 9e92c9ea12 | |||
| a503a54240 | |||
| 265957712a | |||
| c26962bb71 | |||
| a428eddf93 | |||
| dc4f7eb2f9 | |||
| d54ac1ba91 | |||
| a3d46b18ac | |||
| e81dd05666 | |||
| 29394935e3 | |||
| df8acc4ed7 | |||
| 81928d4ab1 | |||
| 3ebf93e03d | |||
| 59e4032f1f | |||
| 8f15777427 | |||
| 748c4bf780 | |||
| befcf6d2b3 | |||
| 48236ecd3c | |||
| f340f84de7 | |||
| 40e19293f9 | |||
| f252f824a4 | |||
| 1d7e5a8130 | |||
| cb2ff92c2f | |||
| ef373ab54f | |||
| 9141a78c29 | |||
| 10a6370738 | |||
| 573009eeb6 | |||
| c3363712d9 | |||
| faa33d89a2 | |||
| f347458c53 | |||
| 530e6d9196 | |||
| b398e18e12 | |||
| 747e8370e0 | |||
| 2c67875781 | |||
| c96e8a8c19 | |||
| 5f203fc082 | |||
| b943c9b471 | |||
| 1a90a1daa8 | |||
| 72dfc743fd | |||
| 465307655b | |||
| 6ce71e6694 | |||
| 7f01b3b92a | |||
| 76950d56b9 | |||
| c11e0d02b3 | |||
| 4c798c1718 | |||
| 450d7e9ad4 | |||
| b8ab79c83e | |||
| 6934bdd533 | |||
| 84dedb73a5 | |||
| 8964aa5221 | |||
| 3481ae236c | |||
| 46adc5f8a4 | |||
| 5296df5899 | |||
| 13dad4be16 | |||
| b5d0c343b4 | |||
| b00b945264 | |||
| 3bda09e105 | |||
| 32d32c4e4a | |||
| 497441b54e | |||
| 9c564fd4c7 | |||
| 0c2263d0e9 | |||
| 3d4d30766d | |||
| 99d84d44fc | |||
| 41ba7077ad | |||
| 8a929a91c3 | |||
| 0604f06841 | |||
| 229924adf9 | |||
| df988b7c69 | |||
| e8106e2e34 | |||
| c21d3e24f8 | |||
| 2d87aa0753 | |||
| b2ad4dc9a0 | |||
| 370f2ea98f | |||
| a05ca565ff | |||
| 52255637f2 | |||
| 0fcaa3a2f5 | |||
| 0e2fa6eb9d | |||
| 1aac462c83 | |||
| 2a0edfd8f7 | |||
| 1f59a9f846 | |||
| 80c20a90ea | |||
| 56a35649fe | |||
| f07cea0b79 | |||
| 4c1b08a281 | |||
| 117f9eddcd | |||
| 7bbbfce482 | |||
| f37a7811f9 | |||
| 9173c10239 | |||
| 318b31550d | |||
| c18ebc63a6 | |||
| d704694272 | |||
| 1cfec3bdf7 | |||
| fe6ea6bc10 | |||
| d29c8df45e | |||
| 71f996af95 | |||
| d9722ad6b3 | |||
| 398fd8028c | |||
| 1345a3cfd3 | |||
| 7eb0b195b8 | |||
| 009caee82d | |||
| 3bdc805a22 | |||
| ac457792b4 | |||
| 1377b54b9e | |||
| 66418ffc8c | |||
| b4c4b1fb70 | |||
| ffe4a4b047 | |||
| 753ce45310 | |||
| fece0d73e7 | |||
| edce076e68 | |||
| 675d0a009a | |||
| 5d41b5a4db | |||
| fe53b135eb | |||
| 5b1c154ee2 | |||
| 816d882611 | |||
| 12bcb09051 | |||
| c59c69a85f | |||
| bdd0daaf6f | |||
| cfad7c8356 | |||
| b2b8a128d0 | |||
| 1cfad80ca2 | |||
| a5a80e41b8 | |||
| 152f8e92bf | |||
| 0323560b49 | |||
| d3bc84a2f7 | |||
| 8a82c259bd | |||
| 46009c7658 | |||
| 6f760308bd | |||
| c346f8f17d | |||
| af1d059fff | |||
| 5562b21a20 | |||
| 8f68f31877 | |||
| ce7e94030c | |||
| ccf5a1b972 | |||
| 0d5ae77efc | |||
| 1695096d18 | |||
| 6db0b7cf18 | |||
| 575b43b0d4 | |||
| 7b39b05894 | |||
| 8bea9e0a5e | |||
| 2255b32e45 | |||
| b62573ae8f | |||
| 44ed84f5cf | |||
| d008c834be | |||
| 2d3a914aee | |||
| 7324f4c3d1 | |||
| 50c8860a50 | |||
| 6456de7188 | |||
| 23c629f2aa | |||
| 2bf154f74f | |||
| b598ad1bc0 | |||
| ace24ad68e | |||
| 750c1a0f27 | |||
| 52d89bd66b | |||
| 8cfb9d35e9 | |||
| 2f529158a0 | |||
| 6e68ab6d9e | |||
| 7a3c55af35 | |||
| fb39d6304a | |||
| 4cb57d9059 | |||
| 42d69bd0e5 | |||
| f27b399f81 | |||
| a545a3938f | |||
| d1e352c9ee | |||
| 99be1e798b | |||
| 2132a28a17 | |||
| 8b1cc28783 | |||
| 78364ac830 | |||
| 6e5f5732b5 | |||
| 87844254d1 | |||
| 08ef9f69fb | |||
| 5fbd1b78e7 | |||
| 39f5eb753f | |||
| f4cbe3f300 | |||
| 70632e5541 | |||
| 0bba700105 | |||
| b71aaccff3 | |||
| 7271ae9611 | |||
| 6e32dff2ad | |||
| 8f7c898c08 | |||
| f4a9815f48 | |||
| 0f8d5c7e98 | |||
| 5e83596a1b | |||
| 6361213e07 | |||
| 9c59a5d9b6 | |||
| bb04844bd5 | |||
| 0b988176fa | |||
| a354f18a2d | |||
| a7ca0fec88 | |||
| 06eec508df | |||
| 10dc580a3a | |||
| 2f6ae3ef01 | |||
| 392e803905 | |||
| 83a5fb585b | |||
| c6205ffbe0 | |||
| c04737ce20 | |||
| 11b92172fe | |||
| 3a6c574376 | |||
| b21ce925fb | |||
| de9dcc4ed6 | |||
| 9e77dbfe20 | |||
| 4cee0676a4 | |||
| 8ad9d21db3 | |||
| 8ba8317eea | |||
| d221187f24 | |||
| db54ec294f | |||
| 1d39796e3f | |||
| cd6a318903 | |||
| 73090b98ab | |||
| 745de1abab | |||
| 961031efc1 | |||
| 2487595778 | |||
| 5c4863d504 | |||
| 5e3a658932 | |||
| cb4704c821 | |||
| cc0b7d1492 | |||
| f8ebbf8b08 | |||
| 8795f60bf1 | |||
| f00c0a9436 | |||
| 767bc71870 | |||
| 4c068e3e00 | |||
| 277d862172 | |||
| dbed6a47bb | |||
| 94f3749784 | |||
| 728e6d851e | |||
| 11e863545f | |||
| dde49f0bb4 | |||
| a37a75aecc | |||
| e43e3aeb1c | |||
| a8fe529814 | |||
| d9f5e2bb08 | |||
| dfa83b0ac8 | |||
| bd5cef1411 | |||
| cd70b48831 | |||
| 50ebf8088a | |||
| c5cfb7eb40 | |||
| bccaafda6d | |||
| bf0086d7b5 | |||
| 7e65938ca6 | |||
| 112eff2509 | |||
| d7837d9179 | |||
| 6cdd057f80 | |||
| 5a03b213fb | |||
| f270213246 | |||
| 2e1795c5ba | |||
| 732d6710d3 | |||
| edf384d2ee | |||
| c307640826 | |||
| a77b598f82 | |||
| 217420cfa5 | |||
| f2b9dff596 | |||
| ae945ed315 | |||
| 770c153c76 | |||
| 29c4a7e606 | |||
| 8875470b37 | |||
| 6e52364bcb | |||
| 7015d616b4 | |||
| 92e6da3260 | |||
| 9220b6f1d5 | |||
| 1d0d538d0c | |||
| 83052eafae | |||
| fa95c3c4a2 | |||
| 665dcf221b | |||
| 8f73dbd253 | |||
| 826312cbad | |||
| 72a18f2b3f | |||
| a6b5e3d0ae | |||
| 1b321f4fa3 | |||
| fbde0b9f35 | |||
| 0e5f5e54cc | |||
| cbb5902066 | |||
| 92ec1b0598 | |||
| a62fc3abff | |||
| 08f8e55446 | |||
| 68f54a3247 | |||
| 29c099fe56 | |||
| 76b81c7b35 | |||
| d6b33ffd6b | |||
| 16b9873fa8 | |||
| ba4a686d1c | |||
| 4be3d79e12 | |||
| 2569b09dbe | |||
| 5d71e69941 | |||
| 16163bf20b | |||
| f1a97fecbd | |||
| a050f82f0e | |||
| ef7beea334 | |||
| 3f4acb33f9 | |||
| 14822e6395 | |||
| e82db4ed38 | |||
| 87b7ea9cf3 | |||
| 787b1fceff | |||
| 140d6ad839 | |||
| 46e8e22236 | |||
| c386db2b33 | |||
| 8dad091c6b | |||
| 3365ccbb9c | |||
| 2ced230965 | |||
| 989d10a3e1 | |||
| 62d8c69774 | |||
| cf704257b0 | |||
| a6cb6f57d3 | |||
| 141c703ed5 | |||
| 796d58867b | |||
| 2f483ec8e8 | |||
| e338918773 | |||
| d9effc58cf | |||
| 05d03f97fc | |||
| 03e891c0e8 | |||
| 4dfe9d52e9 | |||
| 9e65692b69 | |||
| 0687c9a57a | |||
| ffe1287016 | |||
| 75b7e7260f | |||
| d631e081bc | |||
| db5843d904 | |||
| 5ec16153f7 | |||
| 8c873ccdc8 | |||
| c95088f8d5 | |||
| 519fa55df7 | |||
| b8dda033ed | |||
| 0359e9c5c7 | |||
| d822b4a62a | |||
| d9e8c953b1 | |||
| 9eca502026 | |||
| cd0efe3edb | |||
| 8146e9cbcd | |||
| 5d95275024 | |||
| 49a97eea4b | |||
| 36e9c27e9c | |||
| 6e5153cd07 | |||
| c73da864c8 | |||
| 071bb75700 | |||
| 99374de340 | |||
| db7ae4ed5d | |||
| e61f481881 | |||
| 396a3ad2fc | |||
| be235ddc38 | |||
| 9e72ecd93d | |||
| 8e0bd936eb | |||
| 9d0270dcd6 | |||
| 713415c354 | |||
| 786550572e | |||
| 46caeddc81 | |||
| 71bfde2bfe | |||
| 76771b845a | |||
| a74e239e28 | |||
| 6e763b0b42 | |||
| 2f41ece017 | |||
| 01cd5fe0d5 | |||
| ed12ff7bb3 | |||
| f1386bb60d | |||
| 417bd06e76 | |||
| 91e46e3cf8 | |||
| deb5139c4d | |||
| 862ac5d014 | |||
| 028235d421 | |||
| 143d399849 | |||
| 375f171e47 | |||
| 387edcf4b2 | |||
| 011cd37cfb | |||
| 0d4254f319 | |||
| 4c407c2850 | |||
| 829e2d6c5d | |||
| a31c4bd474 | |||
| 17f24dc377 | |||
| de3e9f2809 | |||
| 4442a282e1 | |||
| 261010f23d | |||
| ede44ca6ee | |||
| 452a953234 | |||
| 2b122562ad | |||
| 6891bc3da3 | |||
| b31b8cd7f0 | |||
| e1379ac5ce | |||
| 0ef3f75d7a | |||
| 407a9e5be0 | |||
| 892bb9bf30 | |||
| 47ac871a12 | |||
| a38c3e7f6d | |||
| 08818355d1 | |||
| 0a68afef00 | |||
| 2c0783e327 |
@@ -2,11 +2,17 @@ syntax: regexp
|
||||
|
||||
^\.bzr
|
||||
^ChangeLog
|
||||
^Makevars.global
|
||||
^build
|
||||
^maint
|
||||
|
||||
syntax: glob
|
||||
|
||||
.depend
|
||||
*.qtcreator.{config,creator,creator.user,files,includes}
|
||||
*.sublime-{project,workspace}
|
||||
Makevars.local
|
||||
|
||||
*.a
|
||||
*.dll
|
||||
*.lib
|
||||
@@ -38,10 +44,12 @@ src/*.ttp
|
||||
|
||||
stub/**MMakefile
|
||||
stub/**.*-stamp
|
||||
stub/tmp*/*
|
||||
##stub/tmp*/*
|
||||
stub/tmp*/*.{bin,bin.bindump,bin.disasm,d,map,o,o.disasm}
|
||||
stub/tmp*/mips{,el}.r3000-*.{i,s}
|
||||
stub/**/tmp*/*
|
||||
|
||||
stub/tools/armpe/armpe_tester
|
||||
stub/tools/armpe/armpe_tester{,.exe,.out}
|
||||
|
||||
stub/tools/sstrip/amd64-linux-sstrip
|
||||
stub/tools/sstrip/i386-linux-sstrip
|
||||
|
||||
@@ -1,11 +1,26 @@
|
||||
087cafe682c014863b4aa8a6ea21431251a6ad3c RELEASE_308
|
||||
140415ffbcef86a42b4d672249927364430d3d38 RELEASE_111
|
||||
155618b5b7930f97bd84b82befa7a4fd6672efb3 RELEASE_304
|
||||
1931f4f28074970ec53b4cd21c7fc181b4da8e5e RELEASE_301
|
||||
223ac5b23f9731ceac9ff8d65167df4900776e36 RELEASE_190
|
||||
2c753c5bf38e7322715e2a5c6c5381111bd7a61a RELEASE_194
|
||||
2ee65b77f9117651e2e5517b2edede23698d73ca RELEASE_196
|
||||
396983c065fc743cb5b9703e266ca87eeff8a6ee RELEASE_291
|
||||
46f3a6cca02603000fadc16637b02e30caddd909 RELEASE_302
|
||||
70402aeee6e0e4fc2889658ed8cee44461c0b0a8 RELEASE_200
|
||||
7c6747c82b167368344a238b1a3a87c2a4fa6a18 RELEASE_306
|
||||
95c558f81a0b8d5bb2bede4c8208bb84ae7d1e58 RELEASE_303
|
||||
a1c61174f54aac714f59ac20fcba839d71e64c5c RELEASE_292
|
||||
a916a2fe22de45167d25abcb40008315f415221c RELEASE_201
|
||||
a935d577fc7dd9c2c87761c9c702805da6ce1e51 RELEASE_193
|
||||
b0353253b0b3d062eb5adb50d4b665a96620da45 RELEASE_195
|
||||
b82ef51896199484afe5b0553af7d1e59b7ce428 BRANCHPOINT_FOR_upx2.hg
|
||||
c2e0cd4d621b047f254f2def42132a03683ff52c RELEASE_192
|
||||
c9a983b7da9d4a2311f74366478348412cac2986 RELEASE_305
|
||||
d276aa09033c24d0981bc3f4fee5628aecc988ad RELEASE_290
|
||||
d3989a12c70b0921ff0f7e5e485b398eb12a73b3 RELEASE_309
|
||||
eb1ce56dce7dd1835964362470610925963b9043 RELEASE_110
|
||||
ed96891ef795bceec6b7ff3ca1ca7764431bfb39 RELEASE_191
|
||||
ef9c7f2c9658d73a9b5ab2ed291483d2bbcd8bc7 RELEASE_300
|
||||
efa52753e366300c0e0ebe20631adcb24ed3c15b RELEASE_293
|
||||
fe7acf61147e7031fcc304aae47ca2352056815d RELEASE_307
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ dos/exe
|
||||
watcom/le
|
||||
---------
|
||||
* 16-bit selector alias fixups
|
||||
* 16-bit offset relocation for objects larger than 4 kB
|
||||
* 16-bit offset relocation for objects larger than 4 KiB
|
||||
* 16:16 fixups
|
||||
|
||||
If you need any of the above (they're very rare), send us an URL of a
|
||||
@@ -44,7 +44,7 @@ test file.
|
||||
|
||||
win32/pe
|
||||
--------
|
||||
* writeable shared sections (`--force' *may* work)
|
||||
* writable shared sections (`--force' *may* work)
|
||||
* certificates in the image
|
||||
* compressing files which contain a big BSS requires lots of memory
|
||||
during compression
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
@@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
@@ -225,7 +225,7 @@ impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
@@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
@@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
#
|
||||
# UPX toplevel Makefile - needs GNU make 3.80 or better
|
||||
# UPX toplevel Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
.SUFFIXES:
|
||||
export SHELL = /bin/sh
|
||||
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
|
||||
$(error GNU make 3.81 or better is required)
|
||||
endif
|
||||
|
||||
srcdir = .
|
||||
top_srcdir = .
|
||||
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
|
||||
|
||||
|
||||
# info: src/stub needs GNU make 3.81 and special build tools
|
||||
# info: src/stub needs special build tools
|
||||
BUILD_STUB = 0
|
||||
ifneq ($(wildcard $(HOME)/local/bin/bin-upx/.),)
|
||||
BUILD_STUB = 1
|
||||
@@ -18,9 +25,6 @@ endif
|
||||
ifneq ($(wildcard $(HOME)/bin/bin-upx/.),)
|
||||
BUILD_STUB = 1
|
||||
endif
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.79 3.79.1 3.80),)
|
||||
BUILD_STUB = 0
|
||||
endif
|
||||
|
||||
|
||||
default:
|
||||
@@ -33,15 +37,6 @@ endif
|
||||
$(MAKE) -C src $@
|
||||
$(MAKE) -C doc $@
|
||||
|
||||
# automatically generate ChangeLog from Mercurial repo
|
||||
ChangeLog:
|
||||
ifneq ($(wildcard .hg/data/.),)
|
||||
hg log --style=changelog > $@
|
||||
else
|
||||
@echo "UPX info: no hg repo found"
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: default all mostlyclean clean distclean maintainer-clean
|
||||
.PHONY: ChangeLog
|
||||
|
||||
|
||||
@@ -2,22 +2,123 @@
|
||||
User visible changes for UPX
|
||||
==================================================================
|
||||
|
||||
Changes in 2.90 (08 Oct 2006):
|
||||
Changes in 3.91 (30 Sep 2013):
|
||||
* Added experimental support for Windows 64-bit PE files, based on
|
||||
work by Stefan Widmann. Please use for testing only!
|
||||
* bug fixes
|
||||
|
||||
==================================================================
|
||||
|
||||
Changes in 3.09 (18 Feb 2013):
|
||||
* New option --preserve-build-id for GNU ELF.
|
||||
* Allow for code signing and LC_UUID on Mac OS X executables.
|
||||
* Allow non-contiguous LC_SEGMENTs and 0==.vmsize for Mach-O.
|
||||
* Allow zero-filled final page in PackUnix::canUnpack().
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.08 (12 Dec 2011):
|
||||
* Fix allocation in runtime stub for darwin.macho-entry (i386 and amd64).
|
||||
* Compress shared library on ELF i386 only [ld.so threatens even this case].
|
||||
* Attempt to support ELF on QNX 6.3.0 for armel (experimental).
|
||||
* Better diagnostic when ELF -fPIC is needed.
|
||||
* PT_NOTE improvements for *BSD.
|
||||
* Preserve more ELF .e_flags on ARM.
|
||||
* Minor code improvements for ELF stubs.
|
||||
* Defend against another flavor of corrupt PE header.
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.07 (08 Sep 2010):
|
||||
* win32/pe: fixed relocation handling for files with *no* TLS callbacks
|
||||
[severe bug introduced in 3.06]
|
||||
|
||||
Changes in 3.06 (04 Sep 2010):
|
||||
* win32/pe: TLS callback support contributed by Stefan Widmann. Thanks!
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.05 (27 Apr 2010):
|
||||
* i386-linux and amd64-linux support shared libraries (DT_INIT must
|
||||
exist, all info needed by runtime loader must be first in .text, etc.)
|
||||
* Linux /proc/self/exe now is preserved by default, by leaving behind
|
||||
one page. New compress-time option --unmap-all-pages is available.
|
||||
* Withdraw support for shared libraries on Darwin (Apple Mac OS X)
|
||||
because upx does not understand enough about .dylib.
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.04 (27 Sep 2009):
|
||||
* new format Mach/AMD64 supports 64-bit programs on Apple Macintosh.
|
||||
* new formats Dylib/i386 and Dylib/ppc32 support shared libraries
|
||||
[such as browser plugins] on Darwin (Apple Macintosh). An existing
|
||||
-init function (LC_ROUTINES command) is required.
|
||||
* new format vmlinuz/armel for Debian NSLU2 (etc.) linux kernel
|
||||
* bvmlinuz boot protocol 2.08 for 386 Linux kernel
|
||||
* Extended ABI version 4 for armel-eabi ARM Linux ELF
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.03 (27 Apr 2008):
|
||||
* implement cache flushing for PowerPC (esp. model 440)
|
||||
* fix cache flushing on MIPS (>3 MiB compressed, or with holes)
|
||||
* fix MIPS big-endian
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.02 (16 Dec 2007):
|
||||
* fix unmapping on arm-linux.elf
|
||||
* fix error checking in mmap for i386-linux.elf [triggered by -fPIE]
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.01 (31 Jul 2007):
|
||||
* new options --no-mode, --no-owner and --no-time to disable preservation
|
||||
of mode (file permissions), file ownership and timestamps.
|
||||
* dos/exe: fixed an incorrect error message caused by a bug in
|
||||
relocation handling
|
||||
* new format linux/mipsel supports ELF on [32-bit] R3000
|
||||
* fix argv[0] on PowerPC with --lzma
|
||||
* bug fixes
|
||||
|
||||
Changes in 3.00 (27 Apr 2007):
|
||||
* watcom/le & tmt/adam: fixed a problem when using certain filters
|
||||
|
||||
Changes in 2.93 beta (08 Mar 2007):
|
||||
* new formats Mach/i386 and Mach/fat support Mac OS X i686 and
|
||||
Universal binaries [i686 and PowerPC only]
|
||||
* dos/exe: LZMA is now also supported for 16-bit dos/exe. Please note that
|
||||
you have to explicitly use '--lzma' even for '--ultra-brute' here
|
||||
because runtime decompression is about 30 times slower than NRV -
|
||||
which is really noticeable on old machines.
|
||||
* dos/exe: fixed a rarely occuring bug in relocation handling
|
||||
* win32/pe & arm/pe: better icon compression handling
|
||||
|
||||
Changes in 2.92 beta (23 Jan 2007):
|
||||
* new option '--ultra-brute' which tries even more variants
|
||||
* slightly improved compression ratio for some files when
|
||||
using '--brute' or '--ultra-brute'
|
||||
* bug fixes
|
||||
|
||||
Changes in 2.91 beta (29 Nov 2006):
|
||||
* assorted bug fixes
|
||||
* arm/pe: fix "missing" icon & version info resource problem for wince 5
|
||||
* win32/pe & arm/pe: added option --compress-icons=3 to compress all icons
|
||||
|
||||
Changes in 2.90 beta (08 Oct 2006):
|
||||
* LZMA algorithm support for most of the 32-bit and 64-bit file formats;
|
||||
use new option '--lzma' to enable
|
||||
* new format: BSD/elf386 supporting FreeBSD, NetBSD and OpenBSD
|
||||
via auto-detection of PT_NOTE or EI_OSABI
|
||||
* arm/pe: all the NRV compression methods are now supported
|
||||
(only NRV2D is missing in thumb mode)
|
||||
* linux/elf386, linux/ElfAMD remember /proc/self/exe in environment
|
||||
* vmlinuz/386: fixed zlib uncompression problem on dos
|
||||
* major source code change: the runtime decompression stubs are now
|
||||
* linux/elf386, linux/ElfAMD: remember /proc/self/exe in environment
|
||||
* major source code changes: the runtime decompression stubs are now
|
||||
built from internal ELF objects
|
||||
|
||||
==================================================================
|
||||
|
||||
Changes in 2.03 (07 Nov 2006):
|
||||
* bvmlinuz/386: fix for kernels not at 0x100000; also allow x86_64
|
||||
* linux/elf386: work around Linux kernel bug (0-length .bss needs PF_W)
|
||||
|
||||
Changes in 2.02 (13 Aug 2006):
|
||||
* linux/386: work around Linux kernel bug (".bss" requires PF_W)
|
||||
* linux/ppc32, mach/ppc32: compressed programs now work on a 405 CPU
|
||||
* vmlinuz/386: fixed zlib uncompression problem on dos
|
||||
* vmlinuz/386: fixed zlib uncompression problem on DOS
|
||||
|
||||
Changes in 2.01 (06 Jun 2006):
|
||||
* arm/pe: better DLL support
|
||||
@@ -286,8 +387,8 @@ Changes in 0.80 (03 Aug 1999)
|
||||
* win32/pe: even better TLS support
|
||||
* win32/pe: versioninfo works on NT
|
||||
* win32/pe: import by ordinal from kernel32.dll works
|
||||
* win32/pe: other import improvements: importing a nonexistant DLL
|
||||
results in a usual Windows message, importing a nonexistant function
|
||||
* win32/pe: other import improvements: importing a nonexistent DLL
|
||||
results in a usual Windows message, importing a nonexistent function
|
||||
results in program exit (instead of crash ;-)
|
||||
* win32/pe: new option: '--compress-resources=0'
|
||||
* win32/pe: reduced memory requirement during uncompression, some
|
||||
@@ -339,7 +440,7 @@ Changes in 0.60 (06 Mar 1999)
|
||||
* win32/pe: fixed file corruption when the size of the export data is invalid
|
||||
* win32/pe: fixed a problem with empty resource data
|
||||
* win32/pe: compressed file alignment set to minimum value
|
||||
* win32/pe: made all compressed sections writeable
|
||||
* win32/pe: made all compressed sections writable
|
||||
* fixed some other win32/pe bugs
|
||||
* fixed an address optimization problem for some not Watcom LE files
|
||||
* fixed a bug which could make UPX hang when an exe header contained
|
||||
@@ -380,3 +481,5 @@ Changes in 0.20 (05 Jul 1998)
|
||||
Changes in 0.05 (26 May 1998)
|
||||
* first public beta release
|
||||
|
||||
|
||||
# vim:set syntax=off tw=0 ts=4 sw=4 et: -*- coding: utf-8 -*-
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ THE FUTURE
|
||||
- We will *NOT* add any sort of protection and/or encryption.
|
||||
This only gives people a false feeling of security because
|
||||
by definition all protectors/compressors can be broken.
|
||||
And don't trust any advertisment of authors of other executable
|
||||
And don't trust any advertisement of authors of other executable
|
||||
compressors about this topic - just do a websearch on "unpackers"...
|
||||
|
||||
- Fix all remaining bugs - keep your reports coming ;-)
|
||||
@@ -108,9 +108,9 @@ THE FUTURE
|
||||
COPYRIGHT
|
||||
=========
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
@@ -128,8 +128,8 @@ Share and enjoy,
|
||||
Markus & Laszlo
|
||||
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-9
@@ -8,18 +8,10 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
|
||||
WARNING - UNSTABLE BETA VERSION
|
||||
===============================
|
||||
|
||||
The current stable release is 2.02, and the next stable release
|
||||
will be called version 3.00.
|
||||
|
||||
|
||||
MAJOR NEWS IN UPX 3
|
||||
===================
|
||||
|
||||
|
||||
+17
-8
@@ -69,19 +69,31 @@ Tools needed to build/modify the UPX sources
|
||||
- A C++ compiler supporting inner classes, templates, exceptions
|
||||
and RTTI.
|
||||
|
||||
- GNU make 3.80 or better (GNU make 3.81 recommened).
|
||||
- GNU make 3.81 or better
|
||||
|
||||
- zlib and zlib-devel [or zlib-dev] software packages for your
|
||||
host environment, or via http://www.cygwin.org/setup.exe
|
||||
|
||||
- lzma SDK, such as from https://sourceforge.net/projects/sevenzip/
|
||||
files/LZMA%20SDK/4.43/
|
||||
|
||||
|
||||
To compile the packer sources
|
||||
-----------------------------
|
||||
|
||||
set the environment variable UPX_UCLDIR to point to your
|
||||
UCL installation, e.g.
|
||||
Set the environment variable UPX_UCLDIR to point to your
|
||||
UCL build directory, e.g.
|
||||
|
||||
set UPX_UCLDIR=c:\src\ucl-1.03 (DOS / Windows)
|
||||
export UPX_UCLDIR=$HOME/local/src/ucl-1.03 (Unix)
|
||||
|
||||
then type
|
||||
Set the environment variable UPX_LZMADIR to point to your
|
||||
to your unpacked lzma443.tar.bz2 source directory, e.g.
|
||||
|
||||
export UPX_LZMADIR=$HOME/local/src/lzma-4.43 (Unix)
|
||||
export UPX_LZMA_VERSION=0x443 # perhaps 0x459,0x458,0x457,0x449,0x442
|
||||
|
||||
Finally type
|
||||
|
||||
make
|
||||
|
||||
@@ -89,14 +101,11 @@ To compile the packer sources
|
||||
If you want to modify the stub sources you'll also need
|
||||
-------------------------------------------------------
|
||||
|
||||
- GNU make 3.81 or better
|
||||
http://savannah.gnu.org/projects/make/
|
||||
|
||||
- Perl & Python
|
||||
|
||||
- A number of cross-assemblers and cross-compilers - precompiled
|
||||
binaries for i386-linux hosts are available from
|
||||
http://sourceforge.net/project/showfiles.php?group_id=2331
|
||||
http://sourceforge.net/projects/upx/files/upx-tools/20060823/
|
||||
|
||||
|
||||
Misc. notes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ Ralph Roth <RalphRoth@gmx.net>
|
||||
for reporting several bugs
|
||||
Salvador Eduardo Tropea
|
||||
for beta testing
|
||||
Stefan Widmann
|
||||
for the win32/pe TLS callback support
|
||||
The WINE project (http://www.winehq.com/)
|
||||
for lots of useful information found in their PE loader sources
|
||||
Natascha
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
UPX TODO list. Last updated 2006-03-11.
|
||||
UPX TODO list. Last updated 2006-12-08.
|
||||
|
||||
|
||||
IMPORTANT PROBLEMS THAT SHOULD BE FIXED SOON:
|
||||
@@ -41,8 +41,6 @@ ALL FORMATS
|
||||
- implement `--cpu=486' option to use bswap on the 32-bit formats
|
||||
(if cpu >= 486)
|
||||
|
||||
- consider removing "or ebp,-1" when not needed
|
||||
|
||||
|
||||
FORMAT DJGPP2/COFF
|
||||
==================
|
||||
@@ -86,10 +84,6 @@ FORMAT WATCOM/LE
|
||||
|
||||
- handle holes in the file
|
||||
|
||||
- implement compressWithFilters()
|
||||
|
||||
- add a call to verifyOverlappingDecompression()
|
||||
|
||||
|
||||
FORMAT WIN16/NE
|
||||
===============
|
||||
|
||||
+2
-1
@@ -25,7 +25,7 @@ endif
|
||||
# //
|
||||
# ************************************************************************/
|
||||
|
||||
top_srcdir = ..
|
||||
top_srcdir ?= ..
|
||||
|
||||
PACKAGE = upx
|
||||
VERSION_DATE := $(shell sed -n 's/^.*UPX_VERSION_DATE_ISO .*"\(.*\)".*/\1/p' $(top_srcdir)/src/version.h)
|
||||
@@ -81,4 +81,5 @@ mostlyclean clean distclean maintainer-clean:
|
||||
###
|
||||
|
||||
$(BUILT_SOURCES): $(top_srcdir)/src/version.h $(MAKEFILE_LIST)
|
||||
.DELETE_ON_ERROR: $(BUILT_SOURCES)
|
||||
|
||||
|
||||
+40
-14
@@ -1,5 +1,5 @@
|
||||
Decompressing ELF Directly to Memory on Linux/x86
|
||||
Copyright (C) 2000-2006 John F. Reiser jreiser@BitWagon.com
|
||||
Copyright (C) 2000-2013 John F. Reiser jreiser@BitWagon.com
|
||||
|
||||
References:
|
||||
<elf.h> definitions for the ELF file format
|
||||
@@ -46,8 +46,8 @@ may not be used to take the address of a function.
|
||||
|
||||
The address 0x00400000 was chosen to be out of the way of the usual
|
||||
load address 0x08048000, and to minimize fragmentation in kernel
|
||||
page tables; one page of page tables covers 4MB. The address
|
||||
0x00401000 was chosen as 1 page up from a 64KB boundary, to
|
||||
page tables; one page of page tables covers 4 MiB. The address
|
||||
0x00401000 was chosen as 1 page up from a 64 KiB boundary, to
|
||||
make the startup code and its constants smaller.
|
||||
|
||||
Decompression of the executable begins by decompressing the Elf32_Ehdr
|
||||
@@ -57,23 +57,49 @@ Subroutine do_xmap() of src/stub/l_lx_elf.c performs the
|
||||
"virtual execve()" using the compressed data as source, and stores
|
||||
the decompressed bytes directly into the appropriate virtual addresses.
|
||||
|
||||
Before transfering control to the PT_INTERP "program interpreter",
|
||||
Before transferring control to the PT_INTERP "program interpreter",
|
||||
minor tricks are required to setup the Elf32_auxv_t entries,
|
||||
clear the free portion of the stack (to compensate for ld-linux.so.2
|
||||
assuming that its automatic stack variables are initialized to zero),
|
||||
and remove (all but 4 bytes of) the decompression program (and
|
||||
compressed executable) from the address space.
|
||||
|
||||
Because the UPX runtime stub removes all traces of the compressed file
|
||||
from the address space, then the Linux kernel erases the symlink
|
||||
/proc/self/exe. Linux stores the pathname argument that was specified
|
||||
to execve() immediately after the '\0' which terminates the character
|
||||
string of the last environment variable [as of execve()]. This is true
|
||||
for at least all Linux 2.6, 2.4, and 2.2 kernels. The pathname is not
|
||||
"bound" to the file as strongly as /proc/self/exe (the file may be changed
|
||||
without affecting the pathname), but the pathname does provide some
|
||||
information. The pathname may be relative to the working directory,
|
||||
so look before any chdir().
|
||||
As of upx-3.05, by default on Linux, upon decompression then one page
|
||||
of the compressed executable remains mapped into the address space
|
||||
of the process. If all of the pages of the compressed executable are
|
||||
unmapped, then the Linux kernel erases the symlink /proc/self/exe,
|
||||
and this can cause trouble for the runtime shared library loader
|
||||
expanding $ORIGIN in -rpath, or for application code that relies on
|
||||
/proc/self/exe. Use the compress-time command-line option
|
||||
--unmap-all-pages to achieve that effect at run time. Upx-3.04
|
||||
and previous versions did this by default with no option. However,
|
||||
too much other software erroneously assumes that /proc/self/exe
|
||||
always exists.
|
||||
|
||||
On arm*-linux-elf there is no good address at which to retain one
|
||||
page of the compressed executable. Pages below the usual .p_vaddr
|
||||
0x8000 (32KiB) are rejected by the kernel. Using a page above the
|
||||
original uncompressed brk(0) would require placing the entire initial
|
||||
compressed program above uncompressed brk(0), which would significantly
|
||||
increase the running brk(0); but too many programs break if brk(0)
|
||||
moves. Thus on arm*-linux-elf the compressed executable begins
|
||||
with 0x8000==.p_vaddr, all pages mapped by execve() that are also
|
||||
occupied by decompressed bytes are removed before overwriting, and
|
||||
/proc/self/exe becomes a "(deleted)" symlink. It might be possible
|
||||
to preserve /proc/self/exe if the original uncompressed executable
|
||||
were created with 0x9000==.p_vaddr (one page higher than the usual
|
||||
0x8000) so that the compressed page mapped at 0x8000 would linger.
|
||||
[This has not been tested.]
|
||||
|
||||
Linux stores the pathname argument that was specified to execve()
|
||||
immediately after the '\0' which terminates the character string of the
|
||||
last environment variable [as of execve()]. This is true for at least
|
||||
all Linux 2.6, 2.4, and 2.2 kernels. Linux kernel 2.6.29 and later
|
||||
records a pointer to that character string in Elf32_auxv[AT_EXECFN].
|
||||
The pathname is not "bound" to the file as strongly as /proc/self/exe
|
||||
(the file may be changed without affecting the pathname), but the
|
||||
pathname does provide some information. The pathname may be relative
|
||||
to the working directory, so look before any chdir().
|
||||
|
||||
The Elf formats for Linux add an environment variable named " " [three
|
||||
spaces] which saves the results of readlink("/proc/self/exe",,) before
|
||||
|
||||
+2
-2
@@ -108,14 +108,14 @@ then skip another one - the unfiltering process needs some information
|
||||
to be able to reverse the filtering.
|
||||
|
||||
UPX uses the following idea, which works nicely. First we assume that
|
||||
the size of the area that should be filtered is less than 16MB. Then
|
||||
the size of the area that should be filtered is less than 16 MiB. Then
|
||||
UPX scans over this area and keeps a record of the bytes that are
|
||||
following the 0xE8 bytes. If we are lucky, there will be bytes that
|
||||
were not found following 0xE8. These bytes are our candidates to be
|
||||
used as markers.
|
||||
|
||||
Do you still remember that we assumed that the size of scanned area is
|
||||
less than 16MB? Well, this means that when we process a real call, the
|
||||
less than 16 MiB? Well, this means that when we process a real call, the
|
||||
resulting offset will be less than 0x00FFFFFF too. So the MSB is always
|
||||
0x00. Which is a nice place to store our marker. Of course we should
|
||||
reverse the byte order in the resulting offset - so this marker will
|
||||
|
||||
+1
-1
@@ -45,6 +45,6 @@ These symbols can be defined later in C++ using
|
||||
|
||||
linker->defineSymbol("xx", yy)
|
||||
|
||||
This functionality (we could say it's a simple linker) is achived by
|
||||
This functionality (we could say it's a simple linker) is achieved by
|
||||
compiling the assembly into an ELF object file which a little C++
|
||||
module (src/linker.cpp) can interpret and work with.
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ code 127, and a record will be added to the history file
|
||||
|
||||
In "targeted enforcing" mode, SELinux pays close attention mostly to
|
||||
designated processes that run with elevated privileges: web server,
|
||||
print server, login server, etc. Ordinary user excutables receive
|
||||
print server, login server, etc. Ordinary user executables receive
|
||||
much less scrutiny. However, one of the eventual goals of SELinux is to
|
||||
eradicate runtime generation of instructions because of the possibility
|
||||
for exploitation by malware (virus, trojan, key logger, privilege
|
||||
|
||||
+45
-59
@@ -13,7 +13,7 @@ B<upx> S<[ I<command> ]> S<[ I<options> ]> I<filename>...
|
||||
=head1 ABSTRACT
|
||||
|
||||
The Ultimate Packer for eXecutables
|
||||
Copyright (c) 1996-2006 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
Copyright (c) 1996-2013 Markus Oberhumer, Laszlo Molnar & John Reiser
|
||||
http://upx.sourceforge.net
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ B<UPX> is a versatile executable packer with the following features:
|
||||
- excellent compression ratio: compresses better than zip/gzip,
|
||||
use UPX to decrease the size of your distribution !
|
||||
|
||||
- very fast decompression: about 10 MB/sec on an ancient Pentium 133,
|
||||
about 200 MB/sec on an Athlon XP 2000+.
|
||||
- very fast decompression: about 10 MiB/sec on an ancient Pentium 133,
|
||||
about 200 MiB/sec on an Athlon XP 2000+.
|
||||
|
||||
- no memory overhead for your compressed executables for most of the
|
||||
supported formats
|
||||
@@ -138,6 +138,13 @@ B<--help>: prints the help
|
||||
|
||||
B<--version>: print the version of B<UPX>
|
||||
|
||||
B<--exact>: when compressing, require to be able to get a byte-identical file
|
||||
after decompression with option B<-d>. [NOTE: this is work in progress and is
|
||||
not supported for all formats yet. If you do care, as a workaround you can
|
||||
compress and then decompress your program a first time - any further
|
||||
compress-decompress steps should then yield byte-identical results
|
||||
as compared to the first decompressed version.]
|
||||
|
||||
[ ...to be written... - type `B<upx --help>' for now ]
|
||||
|
||||
|
||||
@@ -146,7 +153,7 @@ B<--version>: print the version of B<UPX>
|
||||
|
||||
B<UPX> offers ten different compression levels from B<-1> to B<-9>,
|
||||
and B<--best>. The default compression level is B<-8> for files
|
||||
smaller than 512 kB, and B<-7> otherwise.
|
||||
smaller than 512 KiB, and B<-7> otherwise.
|
||||
|
||||
=over 4
|
||||
|
||||
@@ -172,38 +179,13 @@ Note that compression level B<--best> can be somewhat slow for large
|
||||
files, but you definitely should use it when releasing a final version
|
||||
of your program.
|
||||
|
||||
Quick start for achieving the best compression ratio:
|
||||
|
||||
=over 4
|
||||
|
||||
Try B<upx --brute myfile.exe>.
|
||||
|
||||
=back
|
||||
|
||||
Details for achieving the best compression ratio:
|
||||
Quick info for achieving the best compression ratio:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
Use the compression level B<--best>.
|
||||
|
||||
=item *
|
||||
|
||||
Try one or both of the options B<--all-methods> and B<--all-filters>.
|
||||
|
||||
=item *
|
||||
|
||||
Try the option B<--crp-ms=NUMBER>. This uses more memory during compression
|
||||
to achieve a (slightly) better compression ratio.
|
||||
|
||||
NUMBER must be a decimal value from 10000 to 999999, inclusive.
|
||||
The default value is 10000 (ten thousand).
|
||||
|
||||
=item *
|
||||
|
||||
Info: the option B<--brute> is an abbrevation for the options
|
||||
B<S<--best> S<--all-methods> S<--all-filters> S<--crp-ms=999999>>.
|
||||
Try B<upx --brute myfile.exe> or even B<upx --ultra-brute myfile.exe>.
|
||||
|
||||
=item *
|
||||
|
||||
@@ -219,7 +201,7 @@ For win32/pe programs there's B<--strip-relocs=0>. See notes below.
|
||||
|
||||
=head1 OVERLAY HANDLING OPTIONS
|
||||
|
||||
Info: An "overlay" means auxillary data atached after the logical end of
|
||||
Info: An "overlay" means auxiliary data attached after the logical end of
|
||||
an executable, and it often contains application specific data
|
||||
(this is a common practice to avoid an extra data file, though
|
||||
it would be better to use resource sections).
|
||||
@@ -367,7 +349,7 @@ Extra options available for this executable format:
|
||||
First of all, it is recommended to use B<UPX> *instead* of B<strip>. strip has
|
||||
the very bad habit of replacing your stub with its own (outdated) version.
|
||||
Additionally B<UPX> corrects a bug/feature in strip v2.8.x: it
|
||||
will fix the 4 KByte aligment of the stub.
|
||||
will fix the 4 KiB alignment of the stub.
|
||||
|
||||
B<UPX> includes the full functionality of stubify. This means it will
|
||||
automatically stubify your COFF files. Use the option B<--coff> to
|
||||
@@ -402,7 +384,7 @@ Extra options available for this executable format:
|
||||
Introduction
|
||||
|
||||
Linux/386 support in UPX consists of 3 different executable formats,
|
||||
one optimized for ELF excutables ("linux/elf386"), one optimized
|
||||
one optimized for ELF executables ("linux/elf386"), one optimized
|
||||
for shell scripts ("linux/sh386"), and one generic format
|
||||
("linux/386").
|
||||
|
||||
@@ -430,14 +412,14 @@ General user's overview
|
||||
or network I/O.
|
||||
|
||||
Depending on the statistics of usage and access, and the relative
|
||||
speeds of CPU, RAM, swap space, /tmp, and filesystem storage, then
|
||||
speeds of CPU, RAM, swap space, /tmp, and file system storage, then
|
||||
invoking and running a compressed executable can be faster than
|
||||
directly running the corresponding uncompressed program.
|
||||
The operating system might perfrom fewer expensive I/O operations
|
||||
The operating system might perform fewer expensive I/O operations
|
||||
to invoke the compressed program. Paging to or from swap space
|
||||
or /tmp might be faster than paging from the general filesystem.
|
||||
or /tmp might be faster than paging from the general file system.
|
||||
``Medium-sized'' programs which access about 1/3 to 1/2 of their
|
||||
stored program bytes can do particulary well with compression.
|
||||
stored program bytes can do particularly well with compression.
|
||||
Small programs tend not to benefit as much because the absolute
|
||||
savings is less. Big programs tend not to benefit proportionally
|
||||
because each invocation may use only a small fraction of the program,
|
||||
@@ -446,7 +428,7 @@ General user's overview
|
||||
then compression may win anyway.
|
||||
|
||||
Currently, executables compressed by UPX do not share RAM at runtime
|
||||
in the way that executables mapped from a filesystem do. As a
|
||||
in the way that executables mapped from a file system do. As a
|
||||
result, if the same program is run simultaneously by more than one
|
||||
process, then using the compressed version will require more RAM and/or
|
||||
swap space. So, shell programs (bash, csh, etc.) and ``make''
|
||||
@@ -535,7 +517,7 @@ The linux/elf386 format decompresses directly into RAM,
|
||||
uses only one exec, does not use space in /tmp,
|
||||
and does not use /proc.
|
||||
|
||||
Linux/elf386 is automatically selected for Linux ELF exectuables.
|
||||
Linux/elf386 is automatically selected for Linux ELF executables.
|
||||
|
||||
Packed programs will be byte-identical to the original after uncompression.
|
||||
|
||||
@@ -624,7 +606,7 @@ Extra options available for this executable format:
|
||||
Please read the general Linux description first.
|
||||
|
||||
The generic linux/386 format decompresses to /tmp and needs
|
||||
/proc filesystem support. It starts the decompressed program
|
||||
/proc file system support. It starts the decompressed program
|
||||
via the execve() syscall.
|
||||
|
||||
Linux/386 is only selected if the specialized linux/elf386
|
||||
@@ -636,11 +618,11 @@ How it works:
|
||||
|
||||
For files which are not ELF and not a script for a known "-c" shell,
|
||||
UPX uses kernel execve(), which first requires decompressing to a
|
||||
temporary file in the filesystem. Interestingly -
|
||||
temporary file in the file system. Interestingly -
|
||||
because of the good memory management of the Linux kernel - this
|
||||
often does not introduce a noticable delay, and in fact there
|
||||
often does not introduce a noticeable delay, and in fact there
|
||||
will be no disk access at all if you have enough free memory as
|
||||
the entire process takes places within the filesystem buffers.
|
||||
the entire process takes places within the file system buffers.
|
||||
|
||||
A compressed executable consists of the UPX stub and an overlay
|
||||
which contains the original program in a compressed form.
|
||||
@@ -666,7 +648,7 @@ Specific drawbacks:
|
||||
decompression, but you still need it for the full execution time
|
||||
of the program.
|
||||
|
||||
- You must have /proc filesystem support as the stub wants to open
|
||||
- You must have /proc file system support as the stub wants to open
|
||||
/proc/<pid>/exe and needs /proc/<pid>/fd/X. This also means that you
|
||||
cannot compress programs that are used during the boot sequence
|
||||
before /proc is mounted.
|
||||
@@ -678,8 +660,8 @@ Specific drawbacks:
|
||||
|
||||
- Because of temporary decompression to disk the decompression speed
|
||||
is not as fast as with the other executable formats. Still, I can see
|
||||
no noticable delay when starting programs like my ~3 MB emacs (which
|
||||
is less than 1 MB when compressed :-).
|
||||
no noticeable delay when starting programs like my ~3 MiB emacs (which
|
||||
is less than 1 MiB when compressed :-).
|
||||
|
||||
Extra options available for this executable format:
|
||||
|
||||
@@ -699,13 +681,16 @@ nostalgic feelings of one of the authors.
|
||||
Packed programs will be byte-identical to the original after uncompression,
|
||||
until further notice.
|
||||
|
||||
Maximum uncompressed size: ~1.89 / ~7.60 Mbytes.
|
||||
Maximum uncompressed size: ~1.89 / ~7.60 MiB.
|
||||
|
||||
Notes:
|
||||
|
||||
- UPX creates as default a suitable executable for CD-Mastering
|
||||
and console transfer. For a CD-Master main executable you could also try
|
||||
the special option "--boot-only" as descriped below.
|
||||
the special option "--boot-only" as described below.
|
||||
It has been reported that upx packed executables are fully compatible with
|
||||
the Sony PlayStation 2 (PS2, PStwo) and Sony PlayStation Portable (PSP) in
|
||||
Sony PlayStation (PSone) emulation mode.
|
||||
|
||||
- Normally the packed files use the same memory areas like the uncompressed
|
||||
versions, so they will not override other memory areas while unpacking.
|
||||
@@ -723,7 +708,7 @@ Extra options available for this executable format:
|
||||
|
||||
--8-bit Uses 8 bit size compression [default: 32 bit]
|
||||
|
||||
--8mb-ram PSone has 8 MB ram available [default: 2 MB]
|
||||
--8mib-ram PSone has 8 MiB ram available [default: 2 MiB]
|
||||
|
||||
--boot-only This format is for main exes and CD-Mastering only !
|
||||
It may slightly improve the compression ratio,
|
||||
@@ -781,7 +766,7 @@ Benefits:
|
||||
- Better compression (but note that the kernel was already compressed,
|
||||
so the improvement is not as large as with other formats).
|
||||
Still, the bytes saved may be essential for special needs like
|
||||
bootdisks.
|
||||
boot disks.
|
||||
|
||||
For example, this is what I get for my 2.2.16 kernel:
|
||||
1589708 vmlinux
|
||||
@@ -828,13 +813,13 @@ Extra options available for this executable format:
|
||||
=head2 NOTES FOR WIN32/PE
|
||||
|
||||
The PE support in B<UPX> is quite stable now, but probably there are
|
||||
still some incompabilities with some files.
|
||||
still some incompatibilities with some files.
|
||||
|
||||
Because of the way B<UPX> (and other packers for this format) works, you
|
||||
can see increased memory usage of your compressed files because the whole
|
||||
program is loaded into memory at startup.
|
||||
If you start several instances of huge compressed programs you're
|
||||
wasting memory because the common segements of the program won't
|
||||
wasting memory because the common segments of the program won't
|
||||
get shared across the instances.
|
||||
On the other hand if you're compressing only smaller programs, or
|
||||
running only one instance of larger programs, then this penalty is
|
||||
@@ -852,8 +837,8 @@ Screensavers are supported, with the restriction that the filename
|
||||
must end with ".scr" (as screensavers are handled slightly different
|
||||
than normal exe files).
|
||||
|
||||
UPX compressed PE files has some minor memory overhead (usually in the
|
||||
10 - 30 kbytes range) which can be seen by specifying the "-i" command
|
||||
UPX compressed PE files have some minor memory overhead (usually in the
|
||||
10 - 30 KiB range) which can be seen by specifying the "-i" command
|
||||
line switch during compression.
|
||||
|
||||
Extra options available for this executable format:
|
||||
@@ -872,6 +857,7 @@ Extra options available for this executable format:
|
||||
--compress-icons=1 Compress all but the first icon.
|
||||
--compress-icons=2 Compress all icons which are not in the
|
||||
first icon directory. [DEFAULT]
|
||||
--compress-icons=3 Compress all icons.
|
||||
|
||||
--compress-resources=0 Don't compress any resources at all.
|
||||
|
||||
@@ -947,13 +933,13 @@ Please report all bugs immediately to the authors.
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
|
||||
This program may be used freely, and you are welcome to
|
||||
redistribute it under certain conditions.
|
||||
|
||||
+49
-39
@@ -1,5 +1,7 @@
|
||||
#
|
||||
# UPX Makefile - needs GNU make 3.80 or better
|
||||
# UPX Makefile - needs GNU make 3.81 or better
|
||||
#
|
||||
# Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
@@ -7,9 +9,19 @@ MAKEFLAGS += -rR
|
||||
export SHELL = /bin/sh
|
||||
override e = $($1) $(EXTRA_$1) $(upx_$1) $($(basename $(notdir $@)).$1)
|
||||
|
||||
srcdir ?= $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
ifneq ($(srcdir),./)
|
||||
ifneq ($(findstring $(firstword $(MAKE_VERSION)),3.77 3.78 3.78.1 3.79 3.79.1 3.80),)
|
||||
$(error GNU make 3.81 or better is required)
|
||||
endif
|
||||
|
||||
ifndef srcdir
|
||||
srcdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
|
||||
srcdir := $(shell echo '$(srcdir)' | sed 's,/*$$,,')
|
||||
endif
|
||||
ifndef top_srcdir
|
||||
top_srcdir := $(srcdir)/..
|
||||
endif
|
||||
include $(wildcard $(top_srcdir)/Makevars.global ./Makevars.local)
|
||||
ifneq ($(srcdir),.)
|
||||
##$(info Info: using VPATH . $(srcdir))
|
||||
VPATH := . $(srcdir)
|
||||
endif
|
||||
@@ -17,18 +29,18 @@ endif
|
||||
ifeq ($(CXX),)
|
||||
CXX = g++
|
||||
endif
|
||||
ifeq ($(firstword $(CXX)),g++)
|
||||
ifneq ($(findstring $(firstword $(CXX)),g++),)
|
||||
USE_GNUC ?= 1
|
||||
endif
|
||||
ifeq ($(USE_GNUC),1)
|
||||
CXXFLAGS += -MMD
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -O0 -g
|
||||
else
|
||||
CXXFLAGS += -O2
|
||||
endif
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Werror
|
||||
##CXXFLAGS += -Wshadow
|
||||
CXXFLAGS_WERROR = -Werror
|
||||
CXXFLAGS += -Wall -W -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wwrite-strings
|
||||
CXXFLAGS += $(CXXFLAGS_WERROR)
|
||||
endif
|
||||
CPPFLAGS += $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)
|
||||
CXXLD ?= $(CXX)
|
||||
@@ -37,7 +49,7 @@ exeext ?= .out
|
||||
libext ?= .a
|
||||
objext ?= .o
|
||||
|
||||
upx_SOURCES := $(wildcard $(srcdir)/*.cpp)
|
||||
upx_SOURCES := $(sort $(wildcard $(srcdir)/*.cpp))
|
||||
upx_OBJECTS := $(notdir $(upx_SOURCES:.cpp=$(objext)))
|
||||
|
||||
# we need UCL and zlib - you can set envvar UPX_UCLDIR
|
||||
@@ -46,59 +58,57 @@ INCLUDES += -I$(UPX_UCLDIR)/include
|
||||
LIBS += $(addprefix -L,$(dir $(wildcard $(UPX_UCLDIR)/libucl$(libext) $(UPX_UCLDIR)/src/.libs/libucl$(libext))))
|
||||
endif
|
||||
LIBS += -lucl -lz
|
||||
# you should set envvar UPX_LZMADIR to point to your unpacked lzma443.tar.bz2
|
||||
ifneq ($(wildcard $(UPX_LZMADIR)/C/7zip/.),)
|
||||
DEFS += -DWITH_LZMA
|
||||
# you should set envvar UPX_LZMADIR to point to your unpacked LZMA SDK
|
||||
include $(top_srcdir)/src/stub/src/c/Makevars.lzma
|
||||
ifneq ($(UPX_LZMA_VERSION),)
|
||||
DEFS += -DWITH_LZMA=$(UPX_LZMA_VERSION)
|
||||
INCLUDES += -I$(UPX_LZMADIR)
|
||||
endif
|
||||
# you should set envvar UPX_LUADIR to point to your unpacked lua-5.1.1.tar.gz
|
||||
# [disabled for now]
|
||||
ifneq ($(wildcard $(UPX_LUADIR)/src/lua.h),)
|
||||
##DEFS += -DWITH_LUA
|
||||
##upx_SOURCES_LUA := $(wildcard $(UPX_LUADIR)/src/*.c)
|
||||
##upx_SOURCES_LUA := $(filter-out %lua.c, $(upx_SOURCES_LUA))
|
||||
##upx_SOURCES_LUA := $(filter-out %luac.c, $(upx_SOURCES_LUA))
|
||||
##upx_OBJECTS_LUA := $(notdir $(upx_SOURCES_LUA:.c=$(objext)))
|
||||
##upx_OBJECTS_LUA := $(addprefix lua_,$(upx_OBJECTS_LUA))
|
||||
##upx_OBJECTS += $(upx_OBJECTS_LUA)
|
||||
else
|
||||
##$(error please set UPX_LUADIR)
|
||||
endif
|
||||
|
||||
|
||||
all: upx$(exeext)
|
||||
all: upx$(exeext) | .depend
|
||||
.DELETE_ON_ERROR: upx$(exeext) $(upx_OBJECTS) .depend
|
||||
|
||||
upx$(exeext): $(upx_OBJECTS) $(upx_DEPENDENCIES)
|
||||
$($(notdir $@).PRE_LINK_STEP)
|
||||
$(strip $(CXXLD) $(call e,CPPFLAGS) $(call e,CXXFLAGS) $(call e,LDFLAGS) -o $@ $(upx_OBJECTS) $(call e,LDADD) $(call e,LIBS))
|
||||
$($(notdir $@).POST_LINK_STEP)
|
||||
|
||||
%.o : %.cpp
|
||||
%.o : %.cpp | .depend
|
||||
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
|
||||
|
||||
.depend: $(sort $(wildcard $(srcdir)/*.cpp $(srcdir)/*.h)) $(MAKEFILE_LIST)
|
||||
@rm -f $@
|
||||
ifeq ($(USE_GNUC),1)
|
||||
@echo "Updating $@"
|
||||
@$(strip $(CXX) $(call e,CPPFLAGS) -MM) $(filter %.cpp,$^) > $@
|
||||
else
|
||||
touch $@
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(USE_GNUC),1)
|
||||
##compress_lzma$(objext) : CXXFLAGS += -O3 -fomit-frame-pointer
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-cast-qual
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-shadow
|
||||
ifeq ($(UPX_LZMA_VERSION),0x443)
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-non-virtual-dtor
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-unused
|
||||
##compress_lzma$(objext) : CXXFLAGS += -Wno-error
|
||||
endif
|
||||
|
||||
ifneq ($(strip $(upx_OBJECTS_LUA)),)
|
||||
$(upx_OBJECTS_LUA) : lua_%.o : $(UPX_LUADIR)/src/%.c
|
||||
$(strip $(CXX) $(call e,CPPFLAGS) $(call e,CXXFLAGS) -o $@ -c $<)
|
||||
ifeq ($(USE_GNUC),1)
|
||||
$(upx_OBJECTS_LUA) : CXXFLAGS += -Wno-cast-align
|
||||
$(upx_OBJECTS_LUA) : CXXFLAGS += -Wno-cast-qual
|
||||
$(upx_OBJECTS_LUA) : CXXFLAGS += -Wno-error
|
||||
endif
|
||||
# needed for gcc-4.3:
|
||||
compress_lzma$(objext) : CXXFLAGS += -Wno-error
|
||||
endif
|
||||
|
||||
|
||||
mostlyclean clean distclean maintainer-clean:
|
||||
rm -f *.d *.map *.o *.obj *.res upx.exe upx.out upx.ttp upx$(exeext)
|
||||
rm -f *.d *.map *.o *.obj *.res .depend upx.exe upx.out upx.ttp upx$(exeext)
|
||||
|
||||
-include *.d
|
||||
.PHONY: all mostlyclean clean distclean maintainer-clean
|
||||
|
||||
ifeq ($(MAKECMDGOALS),mostlyclean)
|
||||
else ifeq ($(MAKECMDGOALS),clean)
|
||||
else ifeq ($(MAKECMDGOALS),distclean)
|
||||
else ifeq ($(MAKECMDGOALS),maintainer-clean)
|
||||
else
|
||||
-include .depend
|
||||
endif
|
||||
|
||||
+191
-78
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_BELE_H
|
||||
#define __UPX_BELE_H
|
||||
#define __UPX_BELE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -88,7 +88,7 @@ inline void set_be32(void *p, unsigned v)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_be64(const void *p)
|
||||
inline upx_uint64_t get_be64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_BE64)
|
||||
return ACC_UA_GET_BE64(p);
|
||||
@@ -97,7 +97,7 @@ inline acc_uint64l_t get_be64(const void *p)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_be64(void *p, acc_uint64l_t v)
|
||||
inline void set_be64(void *p, upx_uint64_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_BE64)
|
||||
ACC_UA_SET_BE64(p, v);
|
||||
@@ -160,7 +160,7 @@ inline void set_le32(void *p, unsigned v)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline acc_uint64l_t get_le64(const void *p)
|
||||
inline upx_uint64_t get_le64(const void *p)
|
||||
{
|
||||
#if defined(ACC_UA_GET_LE64)
|
||||
return ACC_UA_GET_LE64(p);
|
||||
@@ -169,7 +169,7 @@ inline acc_uint64l_t get_le64(const void *p)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void set_le64(void *p, acc_uint64l_t v)
|
||||
inline void set_le64(void *p, upx_uint64_t v)
|
||||
{
|
||||
#if defined(ACC_UA_SET_LE64)
|
||||
ACC_UA_SET_LE64(p, v);
|
||||
@@ -183,81 +183,142 @@ inline void set_le64(void *p, acc_uint64l_t v)
|
||||
// get signed values, i.e. sign-extend
|
||||
**************************************************************************/
|
||||
|
||||
inline int sign_extend(int v, int bits)
|
||||
inline int sign_extend(unsigned v, unsigned bits)
|
||||
{
|
||||
const unsigned sign_bit = 1u << (bits - 1);
|
||||
v |= 0u - (v & sign_bit);
|
||||
return v;
|
||||
v &= sign_bit | (sign_bit - 1);
|
||||
//v = (v ^ sign_bit) - sign_bit;
|
||||
v |= 0 - (v & sign_bit);
|
||||
return (int) v;
|
||||
}
|
||||
|
||||
inline acc_int64l_t sign_extend(acc_int64l_t v, int bits)
|
||||
inline upx_int64_t sign_extend(upx_uint64_t v, unsigned bits)
|
||||
{
|
||||
const acc_uint64l_t sign_bit = ACC_UINT64_C(1) << (bits - 1);
|
||||
v |= ACC_UINT64_C(0) - (v & sign_bit);
|
||||
return v;
|
||||
const upx_uint64_t sign_bit = UPX_UINT64_C(1) << (bits - 1);
|
||||
v &= sign_bit | (sign_bit - 1);
|
||||
//v = (v ^ sign_bit) - sign_bit;
|
||||
v |= 0 - (v & sign_bit);
|
||||
return (upx_int64_t) v;
|
||||
}
|
||||
|
||||
inline int get_be16_signed(const void *p)
|
||||
{
|
||||
int v = get_be16(p);
|
||||
unsigned v = get_be16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_be24_signed(const void *p)
|
||||
{
|
||||
int v = get_be24(p);
|
||||
unsigned v = get_be24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_be32_signed(const void *p)
|
||||
{
|
||||
int v = get_be32(p);
|
||||
unsigned v = get_be32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline acc_int64l_t get_be64_signed(const void *p)
|
||||
inline upx_int64_t get_be64_signed(const void *p)
|
||||
{
|
||||
acc_int64l_t v = get_be64(p);
|
||||
upx_uint64_t v = get_be64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
inline int get_le16_signed(const void *p)
|
||||
{
|
||||
int v = get_le16(p);
|
||||
unsigned v = get_le16(p);
|
||||
return sign_extend(v, 16);
|
||||
}
|
||||
|
||||
inline int get_le24_signed(const void *p)
|
||||
{
|
||||
int v = get_le24(p);
|
||||
unsigned v = get_le24(p);
|
||||
return sign_extend(v, 24);
|
||||
}
|
||||
|
||||
inline int get_le32_signed(const void *p)
|
||||
{
|
||||
int v = get_le32(p);
|
||||
unsigned v = get_le32(p);
|
||||
return sign_extend(v, 32);
|
||||
}
|
||||
|
||||
inline acc_int64l_t get_le64_signed(const void *p)
|
||||
inline upx_int64_t get_le64_signed(const void *p)
|
||||
{
|
||||
acc_int64l_t v = get_le64(p);
|
||||
upx_uint64_t v = get_le64(p);
|
||||
return sign_extend(v, 64);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// swab (bswap)
|
||||
**************************************************************************/
|
||||
|
||||
inline unsigned acc_swab16(unsigned v)
|
||||
{
|
||||
return ((v & 0x00ff) << 8) |
|
||||
((v & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
inline unsigned acc_swab32(unsigned v)
|
||||
{
|
||||
return ((v & 0x000000ff) << 24) |
|
||||
((v & 0x0000ff00) << 8) |
|
||||
((v & 0x00ff0000) >> 8) |
|
||||
((v & 0xff000000) >> 24);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned acc_swab16p(const upx_uint16_t *p)
|
||||
{
|
||||
return acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline unsigned acc_swap32p(const upx_uint32_t *p)
|
||||
{
|
||||
return acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
inline void acc_swab16s(upx_uint16_t *p)
|
||||
{
|
||||
*p = (upx_uint16_t) acc_swab16(*p);
|
||||
}
|
||||
|
||||
inline void acc_swab32s(upx_uint32_t *p)
|
||||
{
|
||||
*p = (upx_uint32_t) acc_swab32(*p);
|
||||
}
|
||||
|
||||
|
||||
inline void acc_ua_swab16s(void *p)
|
||||
{
|
||||
set_be16(p, get_le16(p));
|
||||
}
|
||||
|
||||
inline void acc_ua_swab32s(void *p)
|
||||
{
|
||||
set_be32(p, get_le32(p));
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// classes for portable unaligned access
|
||||
//
|
||||
// Important: these classes must be PODs (Plain Old Data), i.e. no
|
||||
// constructor, no destructor, no virtual functions and no default
|
||||
// assignment operator, and all fields must be public(!).
|
||||
//
|
||||
// [Actually we _can_ use a safe non-POD subset, but for this we need
|
||||
// to have gcc bug 17519 fixed - see http://gcc.gnu.org/PR17519 ]
|
||||
**************************************************************************/
|
||||
|
||||
struct BE16
|
||||
{
|
||||
__packed_struct(BE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline BE16() { }
|
||||
//BE16(unsigned v) { set_be16(d, v); }
|
||||
|
||||
BE16& operator = (unsigned v) { set_be16(d, v); return *this; }
|
||||
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; }
|
||||
BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; }
|
||||
@@ -270,14 +331,15 @@ struct BE16
|
||||
BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE32
|
||||
{
|
||||
__packed_struct(BE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline BE32() { }
|
||||
//BE32(unsigned v) { set_be32(d, v); }
|
||||
|
||||
BE32& operator = (unsigned v) { set_be32(d, v); return *this; }
|
||||
BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; }
|
||||
BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; }
|
||||
@@ -290,34 +352,36 @@ struct BE32
|
||||
BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_be32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct BE64
|
||||
{
|
||||
__packed_struct(BE64)
|
||||
unsigned char d[8];
|
||||
|
||||
BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
||||
BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
||||
BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; }
|
||||
BE64& operator /= (acc_uint64l_t v) { set_be64(d, get_be64(d) / v); return *this; }
|
||||
BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
||||
BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
||||
BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
|
||||
//inline BE64() { }
|
||||
//BE64(upx_uint64_t v) { set_be64(d, v); }
|
||||
|
||||
BE64& operator = (upx_uint64_t v) { set_be64(d, v); return *this; }
|
||||
BE64& operator += (upx_uint64_t v) { set_be64(d, get_be64(d) + v); return *this; }
|
||||
BE64& operator -= (upx_uint64_t v) { set_be64(d, get_be64(d) - v); return *this; }
|
||||
BE64& operator *= (upx_uint64_t v) { set_be64(d, get_be64(d) * v); return *this; }
|
||||
BE64& operator /= (upx_uint64_t v) { set_be64(d, get_be64(d) / v); return *this; }
|
||||
BE64& operator &= (upx_uint64_t v) { set_be64(d, get_be64(d) & v); return *this; }
|
||||
BE64& operator |= (upx_uint64_t v) { set_be64(d, get_be64(d) | v); return *this; }
|
||||
BE64& operator ^= (upx_uint64_t v) { set_be64(d, get_be64(d) ^ v); return *this; }
|
||||
BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; }
|
||||
BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_be64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
operator upx_uint64_t () const { return get_be64(d); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE16
|
||||
{
|
||||
__packed_struct(LE16)
|
||||
unsigned char d[2];
|
||||
|
||||
//inline LE16() { }
|
||||
//LE16(unsigned v) { set_le16(d, v); }
|
||||
|
||||
LE16& operator = (unsigned v) { set_le16(d, v); return *this; }
|
||||
LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; }
|
||||
LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; }
|
||||
@@ -330,14 +394,15 @@ struct LE16
|
||||
LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le16(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE32
|
||||
{
|
||||
__packed_struct(LE32)
|
||||
unsigned char d[4];
|
||||
|
||||
//inline LE32() { }
|
||||
//LE32(unsigned v) { set_le32(d, v); }
|
||||
|
||||
LE32& operator = (unsigned v) { set_le32(d, v); return *this; }
|
||||
LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; }
|
||||
LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; }
|
||||
@@ -350,28 +415,28 @@ struct LE32
|
||||
LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; }
|
||||
|
||||
operator unsigned () const { return get_le32(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
struct LE64
|
||||
{
|
||||
__packed_struct(LE64)
|
||||
unsigned char d[8];
|
||||
|
||||
LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
||||
LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
||||
LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; }
|
||||
LE64& operator /= (acc_uint64l_t v) { set_le64(d, get_le64(d) / v); return *this; }
|
||||
LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
||||
LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
||||
LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
|
||||
//inline LE64() { }
|
||||
//LE64(upx_uint64_t v) { set_le64(d, v); }
|
||||
|
||||
LE64& operator = (upx_uint64_t v) { set_le64(d, v); return *this; }
|
||||
LE64& operator += (upx_uint64_t v) { set_le64(d, get_le64(d) + v); return *this; }
|
||||
LE64& operator -= (upx_uint64_t v) { set_le64(d, get_le64(d) - v); return *this; }
|
||||
LE64& operator *= (upx_uint64_t v) { set_le64(d, get_le64(d) * v); return *this; }
|
||||
LE64& operator /= (upx_uint64_t v) { set_le64(d, get_le64(d) / v); return *this; }
|
||||
LE64& operator &= (upx_uint64_t v) { set_le64(d, get_le64(d) & v); return *this; }
|
||||
LE64& operator |= (upx_uint64_t v) { set_le64(d, get_le64(d) | v); return *this; }
|
||||
LE64& operator ^= (upx_uint64_t v) { set_le64(d, get_le64(d) ^ v); return *this; }
|
||||
LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; }
|
||||
LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; }
|
||||
|
||||
operator acc_uint64l_t () const { return get_le64(d); }
|
||||
}
|
||||
__attribute_packed;
|
||||
operator upx_uint64_t () const { return get_le64(d); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -417,11 +482,47 @@ template <class T> T* operator + (const LE64& v, T* ptr);
|
||||
template <class T> T* operator - (T* ptr, const LE64& v);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// global overloads
|
||||
**************************************************************************/
|
||||
|
||||
#if 1 && !defined(ALIGN_DOWN)
|
||||
inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); }
|
||||
inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }
|
||||
inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); }
|
||||
inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(UPX_MAX)
|
||||
inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); }
|
||||
inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
|
||||
inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); }
|
||||
inline unsigned UPX_MIN(const BE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
|
||||
|
||||
inline unsigned UPX_MAX(unsigned a, const BE32& b) { return UPX_MAX(a, (unsigned) b); }
|
||||
inline unsigned UPX_MAX(const BE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
|
||||
inline unsigned UPX_MIN(unsigned a, const BE32& b) { return UPX_MIN(a, (unsigned) b); }
|
||||
inline unsigned UPX_MIN(const BE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
|
||||
|
||||
inline unsigned UPX_MAX(unsigned a, const LE16& b) { return UPX_MAX(a, (unsigned) b); }
|
||||
inline unsigned UPX_MAX(const LE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
|
||||
inline unsigned UPX_MIN(unsigned a, const LE16& b) { return UPX_MIN(a, (unsigned) b); }
|
||||
inline unsigned UPX_MIN(const LE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
|
||||
|
||||
inline unsigned UPX_MAX(unsigned a, const LE32& b) { return UPX_MAX(a, (unsigned) b); }
|
||||
inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }
|
||||
inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); }
|
||||
inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// for use with qsort()
|
||||
extern "C" {
|
||||
int __acc_cdecl_qsort be16_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be24_compare(const void *, const void *);
|
||||
int __acc_cdecl_qsort be32_compare(const void *, const void *);
|
||||
@@ -438,13 +539,14 @@ int __acc_cdecl_qsort le16_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le24_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);
|
||||
int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
} // extern "C"
|
||||
|
||||
|
||||
// just for testing...
|
||||
#if !defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if !(ACC_CFG_NO_UNALIGNED)
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200)
|
||||
typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
typedef upx_uint16_t LE16_unaligned __attribute__((__aligned__(1)));
|
||||
typedef upx_uint32_t LE32_unaligned __attribute__((__aligned__(1)));
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
@@ -453,8 +555,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
@@ -463,8 +565,8 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
# endif
|
||||
#endif
|
||||
#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200)
|
||||
typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint16_t LE16_unaligned;
|
||||
typedef __declspec(align(1)) upx_uint32_t LE32_unaligned;
|
||||
# ifndef LE16
|
||||
# define LE16 LE16_unaligned
|
||||
# endif
|
||||
@@ -477,7 +579,7 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Provide namespaces and classes to abtract endianness policies.
|
||||
// Provide namespaces and classes to abstract endianness policies.
|
||||
//
|
||||
// CTP - Compile-Time Polymorphism (templates)
|
||||
// RTP - Run-Time Polymorphism (virtual functions)
|
||||
@@ -485,11 +587,15 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
|
||||
|
||||
// forward declarations
|
||||
namespace N_BELE_CTP {
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
namespace N_BELE_RTP {
|
||||
class AbstractPolicy;
|
||||
class BEPolicy; class LEPolicy;
|
||||
struct AbstractPolicy;
|
||||
struct BEPolicy; struct LEPolicy;
|
||||
extern const BEPolicy be_policy;
|
||||
extern const LEPolicy le_policy;
|
||||
}
|
||||
|
||||
namespace N_BELE_CTP {
|
||||
@@ -504,6 +610,13 @@ namespace N_BELE_RTP {
|
||||
#undef BELE_RTP
|
||||
}
|
||||
|
||||
namespace N_BELE_CTP {
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const BEPolicy*)
|
||||
{ return &N_BELE_RTP::be_policy; }
|
||||
inline const N_BELE_RTP::AbstractPolicy* getRTP(const LEPolicy*)
|
||||
{ return &N_BELE_RTP::le_policy; }
|
||||
}
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
+39
-29
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
// CTP - Compile-Time Polymorphism (templates)
|
||||
# define V static inline
|
||||
# define S static int __acc_cdecl_qsort
|
||||
# define C
|
||||
# define C /*empty*/
|
||||
#elif defined(BELE_RTP)
|
||||
// RTP - Run-Time Polymorphism (virtual functions)
|
||||
# define V virtual
|
||||
@@ -53,24 +53,25 @@
|
||||
#if defined(BELE_RTP)
|
||||
struct AbstractPolicy
|
||||
{
|
||||
virtual inline ~AbstractPolicy() {}
|
||||
inline AbstractPolicy() { }
|
||||
virtual inline ~AbstractPolicy() { }
|
||||
V bool isBE() C = 0;
|
||||
V bool isLE() C = 0;
|
||||
|
||||
V unsigned get16(const void *p) C = 0;
|
||||
V unsigned get24(const void *p) C = 0;
|
||||
V unsigned get32(const void *p) C = 0;
|
||||
V acc_uint64l_t get64(const void *p) C = 0;
|
||||
V upx_uint64_t get64(const void *p) C = 0;
|
||||
|
||||
V void set16(void *p, unsigned v) C = 0;
|
||||
V void set24(void *p, unsigned v) C = 0;
|
||||
V void set32(void *p, unsigned v) C = 0;
|
||||
V void set64(void *p, acc_uint64l_t v) C = 0;
|
||||
V void set64(void *p, upx_uint64_t v) C = 0;
|
||||
|
||||
V unsigned get16_signed(const void *p) C = 0;
|
||||
V unsigned get24_signed(const void *p) C = 0;
|
||||
V unsigned get32_signed(const void *p) C = 0;
|
||||
V acc_uint64l_t get64_signed(const void *p) C = 0;
|
||||
V upx_uint64_t get64_signed(const void *p) C = 0;
|
||||
|
||||
S u16_compare(const void *a, const void *b) C = 0;
|
||||
S u24_compare(const void *a, const void *b) C = 0;
|
||||
@@ -81,6 +82,9 @@ struct AbstractPolicy
|
||||
S u24_compare_signed(const void *a, const void *b) C = 0;
|
||||
S u32_compare_signed(const void *a, const void *b) C = 0;
|
||||
S u64_compare_signed(const void *a, const void *b) C = 0;
|
||||
|
||||
// disable dynamic allocation
|
||||
DISABLE_NEW_DELETE
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -90,14 +94,14 @@ struct BEPolicy
|
||||
: public AbstractPolicy
|
||||
#endif
|
||||
{
|
||||
inline BEPolicy() { }
|
||||
#if defined(BELE_CTP)
|
||||
typedef N_BELE_RTP::BEPolicy RTP_Policy;
|
||||
enum { isBE = 1, isLE = 0 };
|
||||
#elif defined(BELE_RTP)
|
||||
typedef N_BELE_CTP::BEPolicy CTP_Policy;
|
||||
V bool isBE() C { return CTP_Policy::isBE; }
|
||||
V bool isLE() C { return CTP_Policy::isLE; }
|
||||
#endif
|
||||
V bool isBE() C { return true; }
|
||||
V bool isLE() C { return false; }
|
||||
|
||||
typedef BE16 U16;
|
||||
typedef BE32 U32;
|
||||
@@ -109,7 +113,7 @@ struct BEPolicy
|
||||
{ return get_be24(p); }
|
||||
V unsigned get32(const void *p) C
|
||||
{ return get_be32(p); }
|
||||
V acc_uint64l_t get64(const void *p) C
|
||||
V upx_uint64_t get64(const void *p) C
|
||||
{ return get_be64(p); }
|
||||
|
||||
V void set16(void *p, unsigned v) C
|
||||
@@ -118,7 +122,7 @@ struct BEPolicy
|
||||
{ set_be24(p, v); }
|
||||
V void set32(void *p, unsigned v) C
|
||||
{ set_be32(p, v); }
|
||||
V void set64(void *p, acc_uint64l_t v) C
|
||||
V void set64(void *p, upx_uint64_t v) C
|
||||
{ set_be64(p, v); }
|
||||
|
||||
V unsigned get16_signed(const void *p) C
|
||||
@@ -127,7 +131,7 @@ struct BEPolicy
|
||||
{ return get_be24_signed(p); }
|
||||
V unsigned get32_signed(const void *p) C
|
||||
{ return get_be32_signed(p); }
|
||||
V acc_uint64l_t get64_signed(const void *p) C
|
||||
V upx_uint64_t get64_signed(const void *p) C
|
||||
{ return get_be64_signed(p); }
|
||||
|
||||
S u16_compare(const void *a, const void *b) C
|
||||
@@ -152,10 +156,13 @@ struct BEPolicy
|
||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U64)
|
||||
}
|
||||
|
||||
// disable dynamic allocation
|
||||
DISABLE_NEW_DELETE
|
||||
};
|
||||
|
||||
|
||||
@@ -164,14 +171,14 @@ struct LEPolicy
|
||||
: public AbstractPolicy
|
||||
#endif
|
||||
{
|
||||
inline LEPolicy() { }
|
||||
#if defined(BELE_CTP)
|
||||
typedef N_BELE_RTP::LEPolicy RTP_Policy;
|
||||
enum { isBE = 0, isLE = 1 };
|
||||
#elif defined(BELE_RTP)
|
||||
typedef N_BELE_CTP::LEPolicy CTP_Policy;
|
||||
V bool isBE() C { return CTP_Policy::isBE; }
|
||||
V bool isLE() C { return CTP_Policy::isLE; }
|
||||
#endif
|
||||
V bool isBE() C { return false; }
|
||||
V bool isLE() C { return true; }
|
||||
|
||||
typedef LE16 U16;
|
||||
typedef LE32 U32;
|
||||
@@ -183,7 +190,7 @@ struct LEPolicy
|
||||
{ return get_le24(p); }
|
||||
V unsigned get32(const void *p) C
|
||||
{ return get_le32(p); }
|
||||
V acc_uint64l_t get64(const void *p) C
|
||||
V upx_uint64_t get64(const void *p) C
|
||||
{ return get_le64(p); }
|
||||
|
||||
V void set16(void *p, unsigned v) C
|
||||
@@ -192,7 +199,7 @@ struct LEPolicy
|
||||
{ set_le24(p, v); }
|
||||
V void set32(void *p, unsigned v) C
|
||||
{ set_le32(p, v); }
|
||||
V void set64(void *p, acc_uint64l_t v) C
|
||||
V void set64(void *p, upx_uint64_t v) C
|
||||
{ set_le64(p, v); }
|
||||
|
||||
V unsigned get16_signed(const void *p) C
|
||||
@@ -201,7 +208,7 @@ struct LEPolicy
|
||||
{ return get_le24_signed(p); }
|
||||
V unsigned get32_signed(const void *p) C
|
||||
{ return get_le32_signed(p); }
|
||||
V acc_uint64l_t get64_signed(const void *p) C
|
||||
V upx_uint64_t get64_signed(const void *p) C
|
||||
{ return get_le64_signed(p); }
|
||||
|
||||
S u16_compare(const void *a, const void *b) C
|
||||
@@ -226,10 +233,13 @@ struct LEPolicy
|
||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(U64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(U64)
|
||||
}
|
||||
|
||||
// disable dynamic allocation
|
||||
DISABLE_NEW_DELETE
|
||||
};
|
||||
|
||||
|
||||
@@ -249,9 +259,9 @@ struct HostAlignedPolicy
|
||||
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
|
||||
#endif
|
||||
|
||||
typedef acc_uint16e_t U16;
|
||||
typedef acc_uint32e_t U32;
|
||||
typedef acc_uint64l_t U64;
|
||||
typedef upx_uint16_t U16;
|
||||
typedef upx_uint32_t U32;
|
||||
typedef upx_uint64_t U64;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_BPTR_H
|
||||
#define __UPX_BPTR_H
|
||||
#define __UPX_BPTR_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
|
||||
+7
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
FILE *con_term = NULL;
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -84,14 +84,14 @@ static int do_init(FILE *f)
|
||||
if (!acc_isatty(STDIN_FILENO) || !acc_isatty(STDOUT_FILENO) || !acc_isatty(STDERR_FILENO))
|
||||
return con_mode;
|
||||
|
||||
#if defined(USE_ANSI)
|
||||
#if (USE_ANSI)
|
||||
try_init(&console_ansi_mono,f);
|
||||
try_init(&console_ansi_color,f);
|
||||
#endif
|
||||
#if defined(USE_SCREEN)
|
||||
#if (USE_SCREEN)
|
||||
try_init(&console_screen,f);
|
||||
#endif
|
||||
#if defined(USE_AALIB)
|
||||
#if (USE_AALIB)
|
||||
try_init(&console_aalib,f);
|
||||
#endif
|
||||
|
||||
|
||||
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
|
||||
+8
-8
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,13 +22,13 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
|
||||
#if defined(USE_SCREEN)
|
||||
#if (USE_SCREEN)
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
@@ -130,15 +130,15 @@ static int init(FILE *f, int o, int now)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_djgpp2_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_WIN32)
|
||||
#if (USE_SCREEN_WIN32)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_win32_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_VCSA)
|
||||
#if (USE_SCREEN_VCSA)
|
||||
if (!screen)
|
||||
screen = do_construct(screen_vcsa_construct(),fd);
|
||||
#endif
|
||||
#if defined(USE_SCREEN_CURSES)
|
||||
#if (USE_SCREEN_CURSES)
|
||||
if (!screen && o == CON_SCREEN)
|
||||
screen = do_construct(screen_curses_construct(),fd);
|
||||
#endif
|
||||
@@ -298,7 +298,7 @@ static void print0(FILE *f, const char *ss)
|
||||
static bool intro(FILE *f)
|
||||
{
|
||||
UNUSED(f);
|
||||
#if defined(USE_FRAMES)
|
||||
#if (USE_FRAMES)
|
||||
if (screen->intro)
|
||||
return screen->intro(screen,screen_show_frames);
|
||||
#endif
|
||||
|
||||
+28
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ unsigned upx_adler32(const void *buf, unsigned len, unsigned adler)
|
||||
assert(buf != NULL);
|
||||
#if 0
|
||||
return adler32(adler, (const Bytef *) buf, len); // zlib
|
||||
#elif defined(WITH_UCL)
|
||||
#elif (WITH_UCL)
|
||||
return ucl_adler32(adler, (const ucl_bytep) buf, len);
|
||||
#else
|
||||
# error
|
||||
@@ -59,7 +59,7 @@ unsigned upx_crc32(const void *buf, unsigned len, unsigned crc)
|
||||
assert(buf != NULL);
|
||||
#if 0
|
||||
return crc32(crc, (const Bytef *) buf, len); // zlib
|
||||
#elif defined(WITH_UCL)
|
||||
#elif (WITH_UCL)
|
||||
return ucl_crc32(crc, (const ucl_bytep) buf, len);
|
||||
#else
|
||||
# error
|
||||
@@ -106,19 +106,19 @@ int upx_compress ( const upx_bytep src, unsigned src_len,
|
||||
cresult->c_len = 0;
|
||||
#endif
|
||||
|
||||
if (method < 0) {
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_compress(src, src_len, dst, dst_len,
|
||||
cb, method, level, cconf, cresult);
|
||||
@@ -152,19 +152,23 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
if (cresult && cresult->method == 0)
|
||||
cresult = NULL;
|
||||
|
||||
if (method < 0) {
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
#if (WITH_ZLIB)
|
||||
else if (M_IS_DEFLATE(method))
|
||||
r = upx_zlib_decompress(src, src_len, dst, dst_len, method, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown decompression method");
|
||||
@@ -178,8 +182,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
@@ -193,19 +199,19 @@ int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||
assert((int)overlap_overhead > 0);
|
||||
|
||||
if (method < 0) {
|
||||
if (0) {
|
||||
}
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
else if (M_IS_LZMA(method))
|
||||
r = upx_lzma_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_lzma_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_nrv_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_nrv_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
else if (M_IS_NRV2B(method) || M_IS_NRV2D(method) || M_IS_NRV2E(method))
|
||||
r = upx_ucl_test_overlap(buf, src_off, src_len, dst_len, method, cresult);
|
||||
r = upx_ucl_test_overlap(buf, tbuf, src_off, src_len, dst_len, method, cresult);
|
||||
#endif
|
||||
else {
|
||||
throwInternalError("unknown decompression method");
|
||||
|
||||
+43
-13
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,19 +22,20 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_COMPRESS_H
|
||||
#define __UPX_COMPRESS_H
|
||||
#define __UPX_COMPRESS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if defined(WITH_LZMA)
|
||||
#if (WITH_LZMA)
|
||||
const char *upx_lzma_version_string(void);
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
@@ -45,14 +46,17 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
const char *upx_nrv_version_string(void);
|
||||
int upx_nrv_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
@@ -63,14 +67,17 @@ int upx_nrv_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_nrv_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_nrv_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
const char *upx_ucl_version_string(void);
|
||||
int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
@@ -81,8 +88,31 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
|
||||
#if (WITH_ZLIB)
|
||||
const char *upx_zlib_version_string(void);
|
||||
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const upx_compress_config_t *cconf,
|
||||
upx_compress_result_t *cresult );
|
||||
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
#endif
|
||||
|
||||
+529
-176
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,16 +22,38 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#if !defined(WITH_LZMA)
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
void lzma_compress_config_t::reset()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
|
||||
pos_bits.reset();
|
||||
lit_pos_bits.reset();
|
||||
lit_context_bits.reset();
|
||||
dict_size.reset();
|
||||
fast_mode = 2;
|
||||
num_fast_bytes.reset();
|
||||
match_finder_cycles = 0;
|
||||
|
||||
max_num_probs = 0;
|
||||
}
|
||||
|
||||
|
||||
#if !(WITH_LZMA)
|
||||
extern int compress_lzma_dummy;
|
||||
int compress_lzma_dummy = 0;
|
||||
#else
|
||||
#define opt compress_lzma_opt
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
|
||||
|
||||
// INFO: the LZMA SDK is covered by a permissive license which allows
|
||||
@@ -71,11 +93,245 @@ int compress_lzma_dummy = 0;
|
||||
// while you keep LZMA SDK code unmodified.
|
||||
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#include "C/7zVersion.h"
|
||||
#if (WITH_LZMA != (0x100 * MY_VER_MAJOR) + (0x10 * (MY_VER_MINOR / 10)) + (MY_VER_MINOR % 10))
|
||||
# error "WITH_LZMA version mismatch"
|
||||
#endif
|
||||
#include "C/Types.h"
|
||||
static void *cb_alloc(void *, size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
static void cb_free(void *, void *ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// cruft because of pseudo-COM layer
|
||||
// compress defaults
|
||||
**************************************************************************/
|
||||
|
||||
#undef USE_LZMA_PROPERTIES
|
||||
static int prepare(lzma_compress_result_t *res,
|
||||
unsigned src_len, int method, int level,
|
||||
const lzma_compress_config_t *lcconf)
|
||||
{
|
||||
// setup defaults
|
||||
res->pos_bits = 2; // 0 .. 4
|
||||
res->lit_pos_bits = 0; // 0 .. 4
|
||||
res->lit_context_bits = 3; // 0 .. 8
|
||||
res->dict_size = 4 * 1024 * 1024; // 1 .. 2**30
|
||||
res->fast_mode = 2;
|
||||
res->num_fast_bytes = 64; // 5 .. 273
|
||||
res->match_finder_cycles = 0;
|
||||
#if 1
|
||||
res->pos_bits = lzma_compress_config_t::pos_bits_t::default_value_c;
|
||||
res->lit_pos_bits = lzma_compress_config_t::lit_pos_bits_t::default_value_c;
|
||||
res->lit_context_bits = lzma_compress_config_t::lit_context_bits_t::default_value_c;
|
||||
res->dict_size = lzma_compress_config_t::dict_size_t::default_value_c;
|
||||
res->num_fast_bytes = lzma_compress_config_t::num_fast_bytes_t::default_value_c;
|
||||
#endif
|
||||
// method overrides
|
||||
if (method >= 0x100) {
|
||||
res->pos_bits = (method >> 16) & 15;
|
||||
res->lit_pos_bits = (method >> 12) & 15;
|
||||
res->lit_context_bits = (method >> 8) & 15;
|
||||
}
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MiB of stack during runtime decompression.
|
||||
res->lit_pos_bits = 4;
|
||||
res->lit_context_bits = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
res->num_fast_bytes = 8;
|
||||
break;
|
||||
case 2:
|
||||
res->dict_size = 256 * 1024;
|
||||
res->fast_mode = 0;
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
res->dict_size = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
res->dict_size = src_len;
|
||||
break;
|
||||
default:
|
||||
goto error;
|
||||
}
|
||||
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(res->pos_bits, lcconf->pos_bits);
|
||||
oassign(res->lit_pos_bits, lcconf->lit_pos_bits);
|
||||
oassign(res->lit_context_bits, lcconf->lit_context_bits);
|
||||
oassign(res->dict_size, lcconf->dict_size);
|
||||
oassign(res->num_fast_bytes, lcconf->num_fast_bytes);
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (res->dict_size > src_len)
|
||||
res->dict_size = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (lcconf && lcconf->max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
if (n <= lcconf->max_num_probs)
|
||||
break;
|
||||
if (res->lit_pos_bits > res->lit_context_bits)
|
||||
{
|
||||
if (res->lit_pos_bits == 0)
|
||||
goto error;
|
||||
res->lit_pos_bits -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (res->lit_context_bits == 0)
|
||||
goto error;
|
||||
res->lit_context_bits -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
//printf("\nlzma_compress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
#define _7ZIP_ST 1
|
||||
#define kLiteralNextStates kLiteralNextStates_enc
|
||||
#include "C/LzmaEnc.h"
|
||||
#include "C/LzmaEnc.c"
|
||||
#include "C/LzFind.c"
|
||||
#undef kLiteralNextStates
|
||||
#undef kNumFullDistances
|
||||
|
||||
|
||||
struct upx_ICompressProgress {
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
upx_callback_p cb;
|
||||
};
|
||||
|
||||
static SRes cb_progress(void *p, UInt64 inSize, UInt64 outSize) {
|
||||
upx_callback_p cb = ((upx_ICompressProgress *) p)->cb;
|
||||
if (cb && cb->nprogress)
|
||||
cb->nprogress(cb, (unsigned) inSize, (unsigned) outSize);
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
int method, int level,
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
unsigned dst_avail = *dst_len;
|
||||
*dst_len = 0;
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
upx_ICompressProgress progress;
|
||||
progress.Progress = cb_progress; progress.cb = cb;
|
||||
|
||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
|
||||
CLzmaEncProps props; memset(&props, 0, sizeof(props));
|
||||
props.level = level;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.pb = res->pos_bits;
|
||||
props.lp = res->lit_pos_bits;
|
||||
props.lc = res->lit_context_bits;
|
||||
props.dictSize = res->dict_size;
|
||||
props.algo = res->fast_mode ? 1 : 0;
|
||||
props.fb = res->num_fast_bytes;
|
||||
props.mc = res->match_finder_cycles;
|
||||
|
||||
unsigned char props_buf[LZMA_PROPS_SIZE];
|
||||
SizeT props_buf_size; props_buf_size = LZMA_PROPS_SIZE;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (dst_avail < 1)
|
||||
goto error;
|
||||
dst[0] = 0; // filled below
|
||||
dst += 1; *dst_len += 1; dst_avail -= 1;
|
||||
#else
|
||||
if (dst_avail < 2)
|
||||
goto error;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned tt; tt = res->lit_context_bits + res->lit_pos_bits;
|
||||
dst[0] = ((tt << 3) | res->pos_bits);
|
||||
dst[1] = ((res->lit_pos_bits << 4) | (res->lit_context_bits));
|
||||
dst += 2; *dst_len += 2; dst_avail -= 2;
|
||||
#endif
|
||||
SizeT x_len; x_len = dst_avail;
|
||||
rh = LzmaEncode(dst, &x_len, src, src_len,
|
||||
&props, props_buf, &props_buf_size, 0,
|
||||
(ICompressProgress *) (void *) &progress, &cba, &cba);
|
||||
assert(x_len <= dst_avail);
|
||||
*dst_len += x_len;
|
||||
if (rh == SZ_OK) {
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
dst[-1] = props_buf[0];
|
||||
#endif
|
||||
r = UPX_E_OK;
|
||||
}
|
||||
|
||||
error:
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compress - cruft because of pseudo-COM layer
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef MSDOS
|
||||
#undef OS2
|
||||
@@ -83,59 +339,68 @@ int compress_lzma_dummy = 0;
|
||||
#undef _WIN32_WCE
|
||||
#undef COMPRESS_MF_MT
|
||||
#undef _NO_EXCEPTIONS
|
||||
#include "C/Common/MyInitGuid.h"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# define INITGUID 1
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#else
|
||||
# include "C/Common/MyInitGuid.h"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.h"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.h"
|
||||
#endif
|
||||
|
||||
namespace MyLzma {
|
||||
|
||||
struct InStreamRam: public ISequentialInStream, public CMyUnknownImp
|
||||
struct InStream: public ISequentialInStream, public CMyUnknownImp
|
||||
{
|
||||
virtual ~InStream() { }
|
||||
MY_UNKNOWN_IMP
|
||||
const Byte *Data; size_t Size; size_t Pos;
|
||||
const Byte *b_buf; size_t b_size; size_t b_pos;
|
||||
void Init(const Byte *data, size_t size) {
|
||||
Data = data; Size = size; Pos = 0;
|
||||
b_buf = data; b_size = size; b_pos = 0;
|
||||
}
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
STDMETHODIMP InStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 remain = Size - Pos;
|
||||
if (size > remain) size = remain;
|
||||
memmove(data, Data + Pos, size);
|
||||
Pos += size;
|
||||
size_t remain = b_size - b_pos;
|
||||
if (size > remain) size = (UInt32) remain;
|
||||
memcpy(data, b_buf + b_pos, size);
|
||||
b_pos += size;
|
||||
if (processedSize != NULL) *processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
struct OutStreamRam : public ISequentialOutStream, public CMyUnknownImp
|
||||
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
|
||||
{
|
||||
virtual ~OutStream() { }
|
||||
MY_UNKNOWN_IMP
|
||||
Byte *Data; size_t Size; size_t Pos; bool Overflow;
|
||||
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
|
||||
void Init(Byte *data, size_t size) {
|
||||
Data = data; Size = size; Pos = 0; Overflow = false;
|
||||
b_buf = data; b_size = size; b_pos = 0; overflow = false;
|
||||
}
|
||||
HRESULT WriteByte(Byte b) {
|
||||
if (Pos >= Size) { Overflow = true; return E_FAIL; }
|
||||
Data[Pos++] = b;
|
||||
HRESULT WriteByte(Byte c) {
|
||||
if (b_pos >= b_size) { overflow = true; return E_FAIL; }
|
||||
b_buf[b_pos++] = c;
|
||||
return S_OK;
|
||||
}
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
};
|
||||
|
||||
STDMETHODIMP OutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < size && Pos < Size; i++)
|
||||
Data[Pos++] = ((const Byte *)data)[i];
|
||||
if (processedSize != NULL) *processedSize = i;
|
||||
if (i != size) { Overflow = true; return E_FAIL; }
|
||||
return S_OK;
|
||||
size_t remain = b_size - b_pos;
|
||||
if (size > remain) size = (UInt32) remain, overflow = true;
|
||||
memcpy(b_buf + b_pos, data, size);
|
||||
b_pos += size;
|
||||
if (processedSize != NULL) *processedSize = size;
|
||||
return overflow ? E_FAIL : S_OK;
|
||||
}
|
||||
|
||||
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
|
||||
{
|
||||
virtual ~ProgressInfo() { }
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
|
||||
upx_callback_p cb;
|
||||
@@ -151,6 +416,36 @@ STDMETHODIMP ProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outS
|
||||
} // namespace
|
||||
|
||||
|
||||
#if (ACC_CC_INTELC_GNUC)
|
||||
# pragma warning(disable: 424) // #424: extra ";" ignored
|
||||
#endif
|
||||
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Alloc.c"
|
||||
# include "C/7zCrc.c"
|
||||
# include "C/Compress/Lz/MatchFinder.c"
|
||||
//# include "CPP/7zip/Common/InBuffer.cpp"
|
||||
# include "CPP/7zip/Common/OutBuffer.cpp"
|
||||
# include "CPP/7zip/Common/StreamUtils.cpp"
|
||||
//# include "CPP/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "CPP/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "CPP/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#else
|
||||
# include "C/Common/Alloc.cpp"
|
||||
# include "C/Common/CRC.cpp"
|
||||
//# include "C/7zip/Common/InBuffer.cpp"
|
||||
# include "C/7zip/Common/OutBuffer.cpp"
|
||||
# include "C/7zip/Common/StreamUtils.cpp"
|
||||
# include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//# include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
# include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
# include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#endif
|
||||
#undef RC_NORMALIZE
|
||||
|
||||
|
||||
int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb,
|
||||
@@ -158,15 +453,16 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
assert(M_IS_LZMA(method));
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
|
||||
int r = UPX_E_ERROR;
|
||||
HRESULT rh;
|
||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
|
||||
MyLzma::InStreamRam is; is.AddRef();
|
||||
MyLzma::OutStreamRam os; os.AddRef();
|
||||
MyLzma::InStream is; is.AddRef();
|
||||
MyLzma::OutStream os; os.AddRef();
|
||||
is.Init(src, src_len);
|
||||
os.Init(dst, *dst_len);
|
||||
|
||||
@@ -174,100 +470,36 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
progress.cb = cb;
|
||||
|
||||
NCompress::NLZMA::CEncoder enc;
|
||||
const PROPID propIDs[7] = {
|
||||
NCoderPropID::kPosStateBits, // 0 pb _posStateBits(2)
|
||||
NCoderPropID::kLitPosBits, // 1 lp _numLiteralPosStateBits(0)
|
||||
NCoderPropID::kLitContextBits, // 2 lc _numLiteralContextBits(3)
|
||||
NCoderPropID::kDictionarySize, // 3
|
||||
NCoderPropID::kAlgorithm, // 4 _fastmode
|
||||
NCoderPropID::kNumFastBytes, // 5
|
||||
NCoderPropID::kMatchFinderCycles // 6
|
||||
const PROPID propIDs[8] = {
|
||||
NCoderPropID::kPosStateBits, // 0 pb _posStateBits(2)
|
||||
NCoderPropID::kLitPosBits, // 1 lp _numLiteralPosStateBits(0)
|
||||
NCoderPropID::kLitContextBits, // 2 lc _numLiteralContextBits(3)
|
||||
NCoderPropID::kDictionarySize, // 3 ds
|
||||
NCoderPropID::kAlgorithm, // 4 fm _fastmode
|
||||
NCoderPropID::kNumFastBytes, // 5 fb
|
||||
NCoderPropID::kMatchFinderCycles, // 6 mfc _matchFinderCycles, _cutValue
|
||||
NCoderPropID::kMatchFinder // 7 mf
|
||||
};
|
||||
PROPVARIANT pr[7];
|
||||
PROPVARIANT pr[8];
|
||||
#ifdef COMPRESS_MF_BT4
|
||||
const unsigned nprops = 8;
|
||||
static wchar_t matchfinder[] = L"BT4";
|
||||
assert(NCompress::NLZMA::FindMatchFinder(matchfinder) >= 0);
|
||||
pr[7].vt = VT_BSTR; pr[7].bstrVal = matchfinder;
|
||||
#else
|
||||
const unsigned nprops = 7;
|
||||
#endif
|
||||
pr[0].vt = pr[1].vt = pr[2].vt = pr[3].vt = VT_UI4;
|
||||
pr[4].vt = pr[5].vt = pr[6].vt = VT_UI4;
|
||||
|
||||
// setup defaults
|
||||
pr[0].uintVal = 2; // 0..4
|
||||
pr[1].uintVal = 0; // 0..4
|
||||
pr[2].uintVal = 3; // 0..8
|
||||
pr[3].uintVal = 1024 * 1024;
|
||||
pr[4].uintVal = 2;
|
||||
pr[5].uintVal = 64; // 5..
|
||||
pr[6].uintVal = 0;
|
||||
#if 0
|
||||
// DEBUG - set sizes so that we use a maxmimum amount of stack.
|
||||
// These settings cause res->num_probs == 3147574, i.e. we will
|
||||
// need about 6 MB of stack during runtime decompression.
|
||||
pr[1].uintVal = 4;
|
||||
pr[2].uintVal = 8;
|
||||
#endif
|
||||
|
||||
// FIXME: tune these settings according to level
|
||||
switch (level)
|
||||
{
|
||||
case 1:
|
||||
pr[3].uintVal = 256 * 1024;
|
||||
pr[4].uintVal = 0;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 5:
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
case 7:
|
||||
break;
|
||||
case 8:
|
||||
break;
|
||||
case 9:
|
||||
pr[3].uintVal = 8 * 1024 * 1024;
|
||||
break;
|
||||
case 10:
|
||||
pr[3].uintVal = src_len;
|
||||
break;
|
||||
default:
|
||||
if (prepare(res, src_len, method, level, lcconf) != 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
// limit dictionary size
|
||||
if (pr[3].uintVal > src_len)
|
||||
pr[3].uintVal = src_len;
|
||||
|
||||
// limit num_probs
|
||||
if (cconf_parm && cconf_parm->conf_lzma.max_num_probs)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
unsigned n = 1846 + (768 << (pr[2].uintVal + pr[1].uintVal));
|
||||
if (n <= cconf_parm->conf_lzma.max_num_probs)
|
||||
break;
|
||||
if (pr[1].uintVal > pr[2].uintVal)
|
||||
{
|
||||
if (pr[1].uintVal == 0)
|
||||
goto error;
|
||||
pr[1].uintVal -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pr[2].uintVal == 0)
|
||||
goto error;
|
||||
pr[2].uintVal -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res->pos_bits = pr[0].uintVal;
|
||||
res->lit_pos_bits = pr[1].uintVal;
|
||||
res->lit_context_bits = pr[2].uintVal;
|
||||
res->dict_size = pr[3].uintVal;
|
||||
//res->num_probs = LzmaGetNumProbs(&s.Properties));
|
||||
//res->num_probs = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
|
||||
res->num_probs = 1846 + (768 << (res->lit_context_bits + res->lit_pos_bits));
|
||||
pr[0].uintVal = res->pos_bits;
|
||||
pr[1].uintVal = res->lit_pos_bits;
|
||||
pr[2].uintVal = res->lit_context_bits;
|
||||
pr[3].uintVal = res->dict_size;
|
||||
pr[4].uintVal = res->fast_mode;
|
||||
pr[5].uintVal = res->num_fast_bytes;
|
||||
pr[6].uintVal = res->match_finder_cycles;
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
try {
|
||||
@@ -275,20 +507,20 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
# error
|
||||
#endif
|
||||
|
||||
if (enc.SetCoderProperties(propIDs, pr, 7) != S_OK)
|
||||
if (enc.SetCoderProperties(propIDs, pr, nprops) != S_OK)
|
||||
goto error;
|
||||
if (enc.WriteCoderProperties(&os) != S_OK)
|
||||
goto error;
|
||||
if (os.Overflow) {
|
||||
if (os.overflow) {
|
||||
//r = UPX_E_OUTPUT_OVERRUN;
|
||||
r = UPX_E_NOT_COMPRESSIBLE;
|
||||
goto error;
|
||||
}
|
||||
assert(os.Pos == 5);
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
os.Pos = 1;
|
||||
assert(os.b_pos == 5);
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
os.b_pos = 1;
|
||||
#else
|
||||
os.Pos = 0;
|
||||
os.b_pos = 0;
|
||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
||||
os.WriteByte((t << 3) | res->pos_bits);
|
||||
@@ -298,61 +530,154 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
||||
rh = enc.Code(&is, &os, NULL, NULL, &progress);
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
} catch(...) { return UPX_E_OUT_OF_MEMORY; }
|
||||
} catch (...) { rh = E_OUTOFMEMORY; }
|
||||
#endif
|
||||
|
||||
assert(is.Pos <= src_len);
|
||||
assert(os.Pos <= *dst_len);
|
||||
assert(is.b_pos <= src_len);
|
||||
assert(os.b_pos <= *dst_len);
|
||||
if (rh == E_OUTOFMEMORY)
|
||||
r = UPX_E_OUT_OF_MEMORY;
|
||||
else if (os.Overflow)
|
||||
else if (os.overflow)
|
||||
{
|
||||
assert(os.Pos == *dst_len);
|
||||
assert(os.b_pos == *dst_len);
|
||||
//r = UPX_E_OUTPUT_OVERRUN;
|
||||
r = UPX_E_NOT_COMPRESSIBLE;
|
||||
}
|
||||
else if (rh == S_OK)
|
||||
{
|
||||
assert(is.Pos == src_len);
|
||||
assert(is.b_pos == src_len);
|
||||
r = UPX_E_OK;
|
||||
}
|
||||
|
||||
error:
|
||||
*dst_len = os.Pos;
|
||||
*dst_len = (unsigned) os.b_pos;
|
||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#include "C/Common/Alloc.cpp"
|
||||
#include "C/Common/CRC.cpp"
|
||||
//#include "C/7zip/Common/InBuffer.cpp"
|
||||
#include "C/7zip/Common/OutBuffer.cpp"
|
||||
#include "C/7zip/Common/StreamUtils.cpp"
|
||||
#include "C/7zip/Compress/LZ/LZInWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZ/LZOutWindow.cpp"
|
||||
//#include "C/7zip/Compress/LZMA/LZMADecoder.cpp"
|
||||
#include "C/7zip/Compress/LZMA/LZMAEncoder.cpp"
|
||||
#include "C/7zip/Compress/RangeCoder/RangeCoderBit.cpp"
|
||||
#undef RC_NORMALIZE
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#undef _LZMA_IN_CB
|
||||
#undef _LZMA_OUT_READ
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
|
||||
#undef _LZMA_PROB32
|
||||
#undef _LZMA_LOC_OPT
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
#include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
#include "C/LzmaDec.h"
|
||||
#include "C/LzmaDec.c"
|
||||
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
#define Properties prop
|
||||
assert(M_IS_LZMA(method));
|
||||
// see res->num_probs above
|
||||
COMPILE_TIME_ASSERT(sizeof(CLzmaProb) == 2)
|
||||
COMPILE_TIME_ASSERT(LZMA_PROPS_SIZE == 5)
|
||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||
COMPILE_TIME_ASSERT(LZMA_LIT_SIZE == 768)
|
||||
|
||||
ISzAlloc cba; cba.Alloc = cb_alloc; cba.Free = cb_free;
|
||||
CLzmaDec s; memset(&s, 0, sizeof(s));
|
||||
SizeT srcLen = 0;
|
||||
int r = UPX_E_ERROR;
|
||||
SRes rh;
|
||||
ELzmaStatus status;
|
||||
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
rh = LzmaProps_Decode(&s.Properties, src, src_len);
|
||||
if (rh != 0)
|
||||
goto error;
|
||||
src += 1; src_len -= 1;
|
||||
#else
|
||||
if (src_len < 3)
|
||||
goto error;
|
||||
s.Properties.pb = src[0] & 7;
|
||||
s.Properties.lp = (src[1] >> 4);
|
||||
s.Properties.lc = src[1] & 15;
|
||||
if (s.Properties.pb >= 5) goto error;
|
||||
if (s.Properties.lp >= 5) goto error;
|
||||
if (s.Properties.lc >= 9) goto error;
|
||||
// extra
|
||||
if ((src[0] >> 3) != (int)(s.Properties.lc + s.Properties.lp)) goto error;
|
||||
src += 2; src_len -= 2;
|
||||
#endif
|
||||
s.Properties.dicSize = 0;
|
||||
|
||||
if (cresult)
|
||||
{
|
||||
assert(cresult->method == method);
|
||||
assert(cresult->result_lzma.pos_bits == (unsigned) s.Properties.pb);
|
||||
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaProps_GetNumProbs(&s.Properties));
|
||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
UNUSED(res);
|
||||
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
}
|
||||
|
||||
rh = LzmaDec_AllocateProbs2(&s, &s.Properties, &cba);
|
||||
if (rh != SZ_OK)
|
||||
{
|
||||
r = UPX_E_OUT_OF_MEMORY;
|
||||
goto error;
|
||||
}
|
||||
|
||||
s.dic = dst; s.dicPos = 0; s.dicBufSize = *dst_len;
|
||||
LzmaDec_Init(&s);
|
||||
srcLen = src_len;
|
||||
rh = LzmaDec_DecodeToDic(&s, *dst_len, src, &srcLen, LZMA_FINISH_ANY, &status);
|
||||
assert(srcLen <= src_len);
|
||||
assert(s.dicPos <= *dst_len);
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_NEEDS_MORE_INPUT)
|
||||
rh = SZ_ERROR_INPUT_EOF;
|
||||
if (rh == SZ_OK && status == LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK)
|
||||
{
|
||||
r = UPX_E_OK;
|
||||
if (srcLen != src_len)
|
||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||
}
|
||||
error:
|
||||
*dst_len = s.dicPos;
|
||||
LzmaDec_FreeProbs(&s, &cba);
|
||||
return r;
|
||||
#undef Properties
|
||||
}
|
||||
|
||||
|
||||
#endif /* (WITH_LZMA >= 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// decompress
|
||||
**************************************************************************/
|
||||
|
||||
#if (WITH_LZMA < 0x461)
|
||||
|
||||
#undef _LZMA_IN_CB
|
||||
#undef _LZMA_OUT_READ
|
||||
#undef _LZMA_PROB32
|
||||
#undef _LZMA_LOC_OPT
|
||||
#if (WITH_LZMA >= 0x449)
|
||||
# include "C/Compress/Lzma/LzmaDecode.h"
|
||||
# include "C/Compress/Lzma/LzmaDecode.c"
|
||||
#else
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.h"
|
||||
# include "C/7zip/Compress/LZMA_C/LzmaDecode.c"
|
||||
#endif
|
||||
|
||||
int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
// see res->num_probs above
|
||||
COMPILE_TIME_ASSERT(sizeof(CProb) == 2)
|
||||
COMPILE_TIME_ASSERT(LZMA_BASE_SIZE == 1846)
|
||||
@@ -363,7 +688,7 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
int r = UPX_E_ERROR;
|
||||
int rh;
|
||||
|
||||
#if defined(USE_LZMA_PROPERTIES)
|
||||
#if (USE_LZMA_PROPERTIES)
|
||||
if (src_len < 2)
|
||||
goto error;
|
||||
rh = LzmaDecodeProperties(&s.Properties, src, src_len);
|
||||
@@ -391,6 +716,9 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
assert(cresult->result_lzma.lit_pos_bits == (unsigned) s.Properties.lp);
|
||||
assert(cresult->result_lzma.lit_context_bits == (unsigned) s.Properties.lc);
|
||||
assert(cresult->result_lzma.num_probs == (unsigned) LzmaGetNumProbs(&s.Properties));
|
||||
const lzma_compress_result_t *res = &cresult->result_lzma;
|
||||
UNUSED(res);
|
||||
//printf("\nlzma_decompress config: %u %u %u %u %u\n", res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs);
|
||||
}
|
||||
s.Probs = (CProb *) malloc(sizeof(CProb) * LzmaGetNumProbs(&s.Properties));
|
||||
if (!s.Probs)
|
||||
@@ -411,35 +739,60 @@ int upx_lzma_decompress ( const upx_bytep src, unsigned src_len,
|
||||
error:
|
||||
*dst_len = dst_out;
|
||||
free(s.Probs);
|
||||
|
||||
UNUSED(cresult);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* (WITH_LZMA < 0x461) */
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
**************************************************************************/
|
||||
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(M_IS_LZMA(method));
|
||||
|
||||
MemBuffer b(src_off + src_len);
|
||||
memcpy(b + src_off, buf + src_off, src_len);
|
||||
unsigned saved_dst_len = *dst_len;
|
||||
int r = upx_lzma_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
||||
if (r != UPX_E_OK)
|
||||
return r;
|
||||
if (*dst_len != saved_dst_len)
|
||||
return UPX_E_ERROR;
|
||||
// NOTE: there is a very tiny possibility that decompression has
|
||||
// succeeded but the data is not restored correctly because of
|
||||
// in-place buffer overlapping.
|
||||
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
int upx_lzma_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
const char *upx_lzma_version_string(void)
|
||||
{
|
||||
assert(method == M_LZMA);
|
||||
|
||||
// FIXME - implement this
|
||||
// Note that Packer::verifyOverlappingDecompression() will
|
||||
// verify the final result in any case.
|
||||
UNUSED(buf);
|
||||
|
||||
unsigned overlap_overhead = src_off + src_len - *dst_len;
|
||||
//printf("upx_lzma_test_overlap: %d\n", overlap_overhead);
|
||||
if ((int)overlap_overhead >= 256)
|
||||
return UPX_E_OK;
|
||||
|
||||
UNUSED(cresult);
|
||||
return UPX_E_ERROR;
|
||||
#if (WITH_LZMA >= 0x461)
|
||||
return MY_VERSION;
|
||||
#elif (WITH_LZMA + 0 == 0x457)
|
||||
return "4.57";
|
||||
#elif (WITH_LZMA + 0 == 0x449)
|
||||
return "4.49";
|
||||
#elif (WITH_LZMA + 0 == 0x443)
|
||||
return "4.43";
|
||||
#else
|
||||
# error "unknown WITH_LZMA version"
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
+37
-18
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,29 +22,29 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#if !defined(WITH_UCL)
|
||||
#if !(WITH_UCL)
|
||||
extern int compress_ucl_dummy;
|
||||
int compress_ucl_dummy = 0;
|
||||
#else
|
||||
|
||||
#if 1 && !defined(UCL_USE_ASM) && (ACC_ARCH_I386)
|
||||
# if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
# define UCL_USE_ASM
|
||||
#if 1 && !(UCL_USE_ASM) && (ACC_ARCH_I386)
|
||||
# if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_MSC || ACC_CC_WATCOMC)
|
||||
# define UCL_USE_ASM 1
|
||||
# endif
|
||||
#endif
|
||||
#if defined(UCL_NO_ASM)
|
||||
#if (UCL_NO_ASM)
|
||||
# undef UCL_USE_ASM
|
||||
#endif
|
||||
#if defined(ACC_CFG_NO_UNALIGNED)
|
||||
#if (ACC_CFG_NO_UNALIGNED)
|
||||
# undef UCL_USE_ASM
|
||||
#endif
|
||||
#if 1 && defined(UCL_USE_ASM)
|
||||
#if 1 && (UCL_USE_ASM)
|
||||
# include <ucl/ucl_asm.h>
|
||||
# define ucl_nrv2b_decompress_safe_8 ucl_nrv2b_decompress_asm_safe_8
|
||||
# define ucl_nrv2b_decompress_safe_le16 ucl_nrv2b_decompress_asm_safe_le16
|
||||
@@ -84,13 +84,14 @@ static int convert_errno_from_ucl(int r)
|
||||
}
|
||||
|
||||
|
||||
static void wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
extern "C" {
|
||||
static void __UCL_CDECL wrap_nprogress_ucl(ucl_uint a, ucl_uint b, int state, ucl_voidp user)
|
||||
{
|
||||
if (state != -1 && state != 3) return;
|
||||
upx_callback_p cb = (upx_callback_p) user;
|
||||
if (cb && cb->nprogress)
|
||||
cb->nprogress(cb, a, b);
|
||||
}
|
||||
}}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -107,6 +108,8 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
int r;
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))
|
||||
|
||||
ucl_progress_callback_t cb;
|
||||
cb.callback = 0;
|
||||
cb.user = NULL;
|
||||
@@ -115,10 +118,9 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
cb.user = cb_parm;
|
||||
}
|
||||
|
||||
ucl_compress_config_t cconf;
|
||||
memset(&cconf, 0xff, sizeof(cconf));
|
||||
ucl_compress_config_t cconf; cconf.reset();
|
||||
if (cconf_parm)
|
||||
cconf = cconf_parm->conf_ucl; // struct copy
|
||||
memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy
|
||||
|
||||
ucl_uint *res = cresult->result_ucl.result;
|
||||
// assume no info available - fill in worst case results
|
||||
@@ -134,7 +136,7 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
// prepare bit-buffer settings
|
||||
cconf.bb_endian = 0;
|
||||
cconf.bb_size = 0;
|
||||
if (method >= M_NRV2B_LE32 && method <= M_CL1B_LE16)
|
||||
if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
|
||||
{
|
||||
static const unsigned char sizes[3] = {32, 8, 16};
|
||||
cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
|
||||
@@ -164,6 +166,10 @@ int upx_ucl_compress ( const upx_bytep src, unsigned src_len,
|
||||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
// make sure first_offset_found is set
|
||||
if (res[6] == 0)
|
||||
res[6] = 1;
|
||||
|
||||
return convert_errno_from_ucl(r);
|
||||
}
|
||||
|
||||
@@ -222,12 +228,15 @@ int upx_ucl_decompress ( const upx_bytep src, unsigned src_len,
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_ucl_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
int r;
|
||||
UNUSED(tbuf); // not needed for UCL
|
||||
|
||||
switch (method)
|
||||
{
|
||||
@@ -268,6 +277,16 @@ int upx_ucl_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
const char *upx_ucl_version_string(void)
|
||||
{
|
||||
return ucl_version_string();
|
||||
}
|
||||
|
||||
|
||||
#endif /* WITH_UCL */
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
/* compress_zlib.cpp --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#include "mem.h"
|
||||
|
||||
|
||||
void zlib_compress_config_t::reset()
|
||||
{
|
||||
memset(this, 0, sizeof(*this));
|
||||
|
||||
mem_level.reset();
|
||||
window_bits.reset();
|
||||
strategy.reset();
|
||||
}
|
||||
|
||||
|
||||
#if !(WITH_ZLIB)
|
||||
extern int compress_zlib_dummy;
|
||||
int compress_zlib_dummy = 0;
|
||||
#else
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
static int convert_errno_from_zlib(int zr)
|
||||
{
|
||||
switch (zr)
|
||||
{
|
||||
case Z_OK: return UPX_E_OK;
|
||||
case Z_DATA_ERROR: return UPX_E_ERROR;
|
||||
case Z_NEED_DICT: return UPX_E_ERROR;
|
||||
}
|
||||
return UPX_E_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_zlib_compress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
upx_callback_p cb_parm,
|
||||
int method, int level,
|
||||
const upx_compress_config_t *cconf_parm,
|
||||
upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_DEFLATE);
|
||||
assert(level > 0); assert(cresult != NULL);
|
||||
UNUSED(cb_parm);
|
||||
int r = UPX_E_ERROR;
|
||||
int zr;
|
||||
const zlib_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_zlib : NULL;
|
||||
zlib_compress_result_t *res = &cresult->result_zlib;
|
||||
|
||||
if (level == 10)
|
||||
level = 9;
|
||||
|
||||
zlib_compress_config_t::mem_level_t mem_level;
|
||||
zlib_compress_config_t::window_bits_t window_bits;
|
||||
zlib_compress_config_t::strategy_t strategy;
|
||||
// cconf overrides
|
||||
if (lcconf)
|
||||
{
|
||||
oassign(mem_level, lcconf->mem_level);
|
||||
oassign(window_bits, lcconf->window_bits);
|
||||
oassign(strategy, lcconf->strategy);
|
||||
}
|
||||
|
||||
res->dummy = 0;
|
||||
|
||||
z_stream s;
|
||||
s.zalloc = (alloc_func) 0;
|
||||
s.zfree = (free_func) 0;
|
||||
s.next_in = const_cast<upx_bytep>(src); // UNCONST
|
||||
s.avail_in = src_len;
|
||||
s.next_out = dst;
|
||||
s.avail_out = *dst_len;
|
||||
s.total_in = s.total_out = 0;
|
||||
|
||||
zr = deflateInit2(&s, level, Z_DEFLATED, 0 - (int)window_bits,
|
||||
mem_level, strategy);
|
||||
if (zr != Z_OK)
|
||||
goto error;
|
||||
zr = deflate(&s, Z_FINISH);
|
||||
if (zr != Z_STREAM_END)
|
||||
goto error;
|
||||
zr = deflateEnd(&s);
|
||||
if (zr != Z_OK)
|
||||
goto error;
|
||||
r = UPX_E_OK;
|
||||
goto done;
|
||||
error:
|
||||
(void) deflateEnd(&s);
|
||||
r = convert_errno_from_zlib(zr);
|
||||
if (r == UPX_E_OK)
|
||||
r = UPX_E_ERROR;
|
||||
done:
|
||||
if (r == UPX_E_OK)
|
||||
{
|
||||
if (s.avail_in != 0 || s.total_in != src_len)
|
||||
r = UPX_E_ERROR;
|
||||
}
|
||||
assert(s.total_in <= src_len);
|
||||
assert(s.total_out <= *dst_len);
|
||||
*dst_len = s.total_out;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int upx_zlib_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_DEFLATE);
|
||||
UNUSED(method);
|
||||
UNUSED(cresult);
|
||||
int r = UPX_E_ERROR;
|
||||
int zr;
|
||||
|
||||
z_stream s;
|
||||
s.zalloc = (alloc_func) 0;
|
||||
s.zfree = (free_func) 0;
|
||||
s.next_in = const_cast<upx_bytep>(src); // UNCONST
|
||||
s.avail_in = src_len;
|
||||
s.next_out = dst;
|
||||
s.avail_out = *dst_len;
|
||||
s.total_in = s.total_out = 0;
|
||||
|
||||
zr = inflateInit2(&s, -15);
|
||||
if (zr != Z_OK)
|
||||
goto error;
|
||||
zr = inflate(&s, Z_FINISH);
|
||||
if (zr != Z_STREAM_END)
|
||||
goto error;
|
||||
zr = inflateEnd(&s);
|
||||
if (zr != Z_OK)
|
||||
goto error;
|
||||
r = UPX_E_OK;
|
||||
goto done;
|
||||
error:
|
||||
(void) inflateEnd(&s);
|
||||
r = convert_errno_from_zlib(zr);
|
||||
if (r == UPX_E_OK)
|
||||
r = UPX_E_ERROR;
|
||||
done:
|
||||
if (r == UPX_E_OK)
|
||||
{
|
||||
if (s.avail_in != 0 || s.total_in != src_len)
|
||||
r = UPX_E_INPUT_NOT_CONSUMED;
|
||||
}
|
||||
assert(s.total_in <= src_len);
|
||||
assert(s.total_out <= *dst_len);
|
||||
*dst_len = s.total_out;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// test_overlap - see <ucl/ucl.h> for semantics
|
||||
**************************************************************************/
|
||||
|
||||
int upx_zlib_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult )
|
||||
{
|
||||
assert(method == M_DEFLATE);
|
||||
|
||||
MemBuffer b(src_off + src_len);
|
||||
memcpy(b + src_off, buf + src_off, src_len);
|
||||
unsigned saved_dst_len = *dst_len;
|
||||
int r = upx_zlib_decompress(b + src_off, src_len, b, dst_len, method, cresult);
|
||||
if (r != UPX_E_OK)
|
||||
return r;
|
||||
if (*dst_len != saved_dst_len)
|
||||
return UPX_E_ERROR;
|
||||
// NOTE: there is a very tiny possibility that decompression has
|
||||
// succeeded but the data is not restored correctly because of
|
||||
// in-place buffer overlapping.
|
||||
if (tbuf != NULL && memcmp(tbuf, b, *dst_len) != 0)
|
||||
return UPX_E_ERROR;
|
||||
return UPX_E_OK;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
const char *upx_zlib_version_string(void)
|
||||
{
|
||||
return zlibVersion();
|
||||
}
|
||||
|
||||
|
||||
#endif /* WITH_ZLIB */
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
+401
-220
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_CONF_H
|
||||
#define __UPX_CONF_H
|
||||
#define __UPX_CONF_H 1
|
||||
|
||||
#include "version.h"
|
||||
|
||||
@@ -36,12 +36,35 @@
|
||||
// ACC
|
||||
**************************************************************************/
|
||||
|
||||
#if (defined(_WIN32) || defined(_WIN64)) && defined(_MSC_VER)
|
||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_NONSTDC_NO_WARNINGS
|
||||
#define _CRT_NONSTDC_NO_WARNINGS 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "miniacc.h"
|
||||
#if ((ACC_OS_WIN32 || ACC_OS_WIN64) && ACC_CC_MWERKS) && defined(__MSL__)
|
||||
# undef HAVE_UTIME_H /* this pulls in <windows.h> */
|
||||
#endif
|
||||
// FIXME - quick hack for arm-wince-gcc-3.4 (Debian pocketpc-*.deb packages)
|
||||
#if 1 && (ACC_ARCH_ARM) && defined(__pe__) && !defined(_WIN32)
|
||||
# undef HAVE_CHMOD
|
||||
# undef HAVE_CHOWN
|
||||
# undef HAVE_LSTAT
|
||||
# undef HAVE_UTIME
|
||||
#endif
|
||||
|
||||
|
||||
// pragmas
|
||||
#if (ACC_CC_BORLANDC)
|
||||
# if (__BORLANDC__ < 0x0500)
|
||||
# error "need Borland C++ 5.0 or newer"
|
||||
@@ -70,10 +93,13 @@
|
||||
# if (ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# elif defined(__linux__)
|
||||
# pragma warning(error: 424) // #424: extra ";" ignored
|
||||
//# pragma warning(disable: 128) // #128: loop is not reachable from preceding code
|
||||
//# pragma warning(disable: 181) // #181: argument is incompatible with corresponding format string conversion
|
||||
# pragma warning(disable: 193) // #193: zero used for undefined preprocessing identifier
|
||||
# pragma warning(disable: 810) // #810: conversion from "A" to "B" may lose significant bits
|
||||
# pragma warning(disable: 981) // #981: operands are evaluated in unspecified order
|
||||
# pragma warning(disable: 1418) // #1418: external definition with no prior declaration
|
||||
# pragma warning(disable: 1418) // #1418: external function definition with no prior declaration
|
||||
//# pragma warning(disable: 1419) // #1419: external declaration in primary source file
|
||||
# else
|
||||
# error "untested platform"
|
||||
# endif
|
||||
@@ -82,6 +108,7 @@
|
||||
# error "need Visual C++ 5.0 or newer"
|
||||
# endif
|
||||
# pragma warning(error: 4096) // W2: '__cdecl' must be used with '...'
|
||||
# pragma warning(error: 4138) // Wx: '*/' found outside of comment
|
||||
# pragma warning(disable: 4097) // W3: typedef-name 'A' used as synonym for class-name 'B'
|
||||
# pragma warning(disable: 4511) // W3: 'class': copy constructor could not be generated
|
||||
# pragma warning(disable: 4512) // W4: 'class': assignment operator could not be generated
|
||||
@@ -96,11 +123,16 @@
|
||||
# if (_MSC_VER >= 1400)
|
||||
# pragma warning(disable: 4996) // W1: 'function': was declared deprecated
|
||||
# endif
|
||||
#elif (ACC_CC_SUNPROC)
|
||||
//# pragma error_messages(off,"badargtype2w") // FIXME
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# if (__WATCOMC__ < 1100)
|
||||
# error "need Watcom C++ 11.0c or newer"
|
||||
# if (__WATCOMC__ < 1280)
|
||||
# error "need Open Watcom C++ 1.8 or newer" // because earlier versions do not support nested classes
|
||||
# endif
|
||||
# if defined(__cplusplus)
|
||||
# pragma warning 367 9 // w3: conditional expression in if statement is always true
|
||||
# pragma warning 368 9 // w3: conditional expression in if statement is always false
|
||||
# pragma warning 389 9 // w3: integral value may be truncated
|
||||
# pragma warning 656 9 // w5: define this function inside its class definition (may improve code quality)
|
||||
# endif
|
||||
#endif
|
||||
@@ -117,6 +149,23 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* intergral types */
|
||||
typedef acc_int8_t upx_int8_t;
|
||||
typedef acc_uint8_t upx_uint8_t;
|
||||
typedef acc_int16_t upx_int16_t;
|
||||
typedef acc_uint16_t upx_uint16_t;
|
||||
typedef acc_int32_t upx_int32_t;
|
||||
typedef acc_uint32_t upx_uint32_t;
|
||||
typedef acc_int64_t upx_int64_t;
|
||||
typedef acc_uint64_t upx_uint64_t;
|
||||
typedef acc_uintptr_t upx_uintptr_t;
|
||||
#define UPX_INT16_C ACC_INT16_C
|
||||
#define UPX_UINT16_C ACC_UINT16_C
|
||||
#define UPX_INT32_C ACC_INT32_C
|
||||
#define UPX_UINT32_C ACC_UINT32_C
|
||||
#define UPX_INT64_C ACC_INT64_C
|
||||
#define UPX_UINT64_C ACC_UINT64_C
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
@@ -127,15 +176,18 @@
|
||||
#endif
|
||||
|
||||
// just in case
|
||||
#undef _
|
||||
#undef __
|
||||
#undef ___
|
||||
#undef NDEBUG
|
||||
#undef dos
|
||||
#undef linux
|
||||
#undef small
|
||||
#undef tos
|
||||
#if defined(ACC_CC_DMC)
|
||||
#if (ACC_CC_DMC)
|
||||
# undef tell
|
||||
#endif
|
||||
#if !defined(ACC_CC_PGI)
|
||||
#if !(ACC_CC_PGI)
|
||||
# undef unix
|
||||
#endif
|
||||
#if defined(__DJGPP__)
|
||||
@@ -150,25 +202,26 @@
|
||||
#if 0 && !defined(WITH_LZMA)
|
||||
# define WITH_LZMA 1
|
||||
#endif
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
# undef WITH_LZMA
|
||||
#endif
|
||||
#if defined(UPX_OFFICIAL_BUILD)
|
||||
# if !defined(WITH_LZMA) || !defined(WITH_NRV) || !defined(WITH_UCL)
|
||||
# if !(WITH_LZMA) || !(WITH_NRV) || !(WITH_UCL)
|
||||
# error
|
||||
# endif
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
# include <nrv/nrvconf.h>
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
# define ucl_compress_config_t REAL_ucl_compress_config_t
|
||||
# include <ucl/uclconf.h>
|
||||
# include <ucl/ucl.h>
|
||||
# if !defined(UCL_VERSION) || (UCL_VERSION < 0x010300L)
|
||||
# error "please upgrade your UCL installation"
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(__UPX_CHECKER)
|
||||
# if defined(__UCL_CHECKER) || defined(__NRV_CHECKER)
|
||||
# define __UPX_CHECKER
|
||||
# endif
|
||||
# undef ucl_compress_config_t
|
||||
# undef ucl_compress_config_p
|
||||
#endif
|
||||
#if !defined(UINT_MAX) || (UINT_MAX < 0xffffffffL)
|
||||
# error "UINT_MAX"
|
||||
@@ -176,91 +229,6 @@
|
||||
|
||||
#define upx_byte unsigned char
|
||||
#define upx_bytep upx_byte *
|
||||
#define UPX_E_OK (0)
|
||||
#define UPX_E_ERROR (-1)
|
||||
#define UPX_E_OUT_OF_MEMORY (-2)
|
||||
#define UPX_E_NOT_COMPRESSIBLE (-3)
|
||||
#define UPX_E_INPUT_OVERRUN (-4)
|
||||
#define UPX_E_OUTPUT_OVERRUN (-5)
|
||||
#define UPX_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define UPX_E_EOF_NOT_FOUND (-7)
|
||||
#define UPX_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define UPX_E_NOT_YET_IMPLEMENTED (-9)
|
||||
#define UPX_E_INVALID_ARGUMENT (-10)
|
||||
|
||||
struct upx_callback_t;
|
||||
#define upx_callback_p upx_callback_t *
|
||||
typedef void* (__acc_cdecl *upx_alloc_func_t)
|
||||
(upx_callback_p self, unsigned items, unsigned size);
|
||||
typedef void (__acc_cdecl *upx_free_func_t)
|
||||
(upx_callback_p self, void* ptr);
|
||||
typedef void (__acc_cdecl *upx_progress_func_t)
|
||||
(upx_callback_p, unsigned, unsigned);
|
||||
|
||||
struct upx_callback_t
|
||||
{
|
||||
#if 0
|
||||
upx_alloc_func_t nalloc;
|
||||
upx_free_func_t nfree;
|
||||
#endif
|
||||
upx_progress_func_t nprogress;
|
||||
void * user1;
|
||||
#if 0
|
||||
unsigned user2;
|
||||
unsigned user3;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
struct lzma_compress_config_t
|
||||
{
|
||||
unsigned max_num_probs;
|
||||
#if 0
|
||||
unsigned pos_bits; // pb
|
||||
unsigned lit_pos_bits; // lp
|
||||
unsigned lit_context_bits; // lc
|
||||
unsigned dict_size;
|
||||
unsigned mf_passes;
|
||||
#endif
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
#define upx_compress_config_p upx_compress_config_t *
|
||||
struct upx_compress_config_t
|
||||
{
|
||||
lzma_compress_config_t conf_lzma;
|
||||
ucl_compress_config_t conf_ucl;
|
||||
void reset() {
|
||||
conf_lzma.reset();
|
||||
memset(&conf_ucl, 0xff, sizeof(conf_ucl));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct lzma_compress_result_t
|
||||
{
|
||||
unsigned pos_bits; // pb
|
||||
unsigned lit_pos_bits; // lp
|
||||
unsigned lit_context_bits; // lc
|
||||
unsigned dict_size;
|
||||
unsigned num_probs;
|
||||
};
|
||||
|
||||
struct ucl_compress_result_t
|
||||
{
|
||||
ucl_uint result[16];
|
||||
};
|
||||
|
||||
struct upx_compress_result_t
|
||||
{
|
||||
#if 1
|
||||
// debug
|
||||
int method, level;
|
||||
unsigned u_len, c_len;
|
||||
#endif
|
||||
lzma_compress_result_t result_lzma;
|
||||
ucl_compress_result_t result_ucl;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -268,37 +236,21 @@ struct upx_compress_result_t
|
||||
**************************************************************************/
|
||||
|
||||
// malloc debuggers
|
||||
#if defined(WITH_VALGRIND)
|
||||
#if (WITH_VALGRIND)
|
||||
# include <valgrind/memcheck.h>
|
||||
#elif defined(WITH_DMALLOC)
|
||||
# define DMALLOC_FUNC_CHECK
|
||||
# include <dmalloc.h>
|
||||
#elif defined(WITH_GC)
|
||||
# define GC_DEBUG
|
||||
# include <gc/gc.h>
|
||||
# undef malloc
|
||||
# undef realloc
|
||||
# undef free
|
||||
# define malloc GC_MALLOC
|
||||
# define realloc GC_REALLOC
|
||||
# define free GC_FREE
|
||||
#endif
|
||||
|
||||
#if !defined(VALGRIND_MAKE_WRITABLE)
|
||||
# define VALGRIND_MAKE_WRITABLE(addr,len) 0
|
||||
#if !defined(VALGRIND_MAKE_MEM_DEFINED)
|
||||
# define VALGRIND_MAKE_MEM_DEFINED(addr,len) 0
|
||||
#endif
|
||||
#if !defined(VALGRIND_MAKE_READABLE)
|
||||
# if 0
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) (memset(addr,0,len), 0)
|
||||
# else
|
||||
# define VALGRIND_MAKE_READABLE(addr,len) 0
|
||||
# endif
|
||||
#if !defined(VALGRIND_MAKE_MEM_NOACCESS)
|
||||
# define VALGRIND_MAKE_MEM_NOACCESS(addr,len) 0
|
||||
#endif
|
||||
#if !defined(VALGRIND_DISCARD)
|
||||
# define VALGRIND_DISCARD(handle) ((void)(&handle))
|
||||
#if !defined(VALGRIND_MAKE_MEM_UNDEFINED)
|
||||
# define VALGRIND_MAKE_MEM_UNDEFINED(addr,len) 0
|
||||
#endif
|
||||
|
||||
|
||||
// unconditionally turn on assertions
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
|
||||
@@ -318,11 +270,11 @@ struct upx_compress_result_t
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_STRCASECMP) && defined(HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
#if !(HAVE_STRCASECMP) && (HAVE_STRICMP)
|
||||
# define strcasecmp stricmp
|
||||
#endif
|
||||
#if !defined(HAVE_STRNCASECMP) && defined(HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
#if !(HAVE_STRNCASECMP) && (HAVE_STRNICMP)
|
||||
# define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
|
||||
@@ -375,18 +327,6 @@ struct upx_compress_result_t
|
||||
#undef PAGE_MASK
|
||||
#undef PAGE_SIZE
|
||||
|
||||
|
||||
#undef __attribute_packed
|
||||
#if (ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE)
|
||||
# if (1 && (ACC_ARCH_I386))
|
||||
# define __attribute_packed
|
||||
# else
|
||||
# define __attribute_packed __attribute__((__packed__,__aligned__(1)))
|
||||
# endif
|
||||
#else
|
||||
# define __attribute_packed
|
||||
#endif
|
||||
|
||||
#if !defined(O_BINARY)
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
@@ -396,6 +336,21 @@ struct upx_compress_result_t
|
||||
#endif
|
||||
|
||||
|
||||
#if (ACC_CC_INTELC && (__INTEL_COMPILER < 800))
|
||||
#elif (0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386))
|
||||
#elif (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC_GNUC || ACC_CC_PATHSCALE)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() } __attribute__((__packed__,__aligned__(1)));
|
||||
#elif (ACC_CC_WATCOMC)
|
||||
# define __packed_struct(s) _Packed struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
#if !defined(__packed_struct)
|
||||
# define __packed_struct(s) struct s {
|
||||
# define __packed_struct_end() };
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
@@ -403,68 +358,53 @@ struct upx_compress_result_t
|
||||
#define UNUSED(var) ACC_UNUSED(var)
|
||||
#define COMPILE_TIME_ASSERT(e) ACC_COMPILE_TIME_ASSERT(e)
|
||||
|
||||
#if 1
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
#define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
typedef a acc_tmp_a_t; typedef b acc_tmp_b_t; \
|
||||
struct acc_tmp_t { acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z[7]; } __attribute_packed; \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||
__packed_struct(acc_tmp_t) acc_tmp_b_t x; acc_tmp_a_t y; acc_tmp_b_t z; __packed_struct_end() \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 2*sizeof(b)+sizeof(a)) \
|
||||
COMPILE_TIME_ASSERT(sizeof(((acc_tmp_t*)0)->x)+sizeof(((acc_tmp_t*)0)->y)+sizeof(((acc_tmp_t*)0)->z) == 2*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#else
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) { \
|
||||
struct acc_tmp_t { b x; a y; b z[7]; } __attribute_packed; \
|
||||
COMPILE_TIME_ASSERT(sizeof(struct acc_tmp_t) == 8*sizeof(b)+sizeof(a)) \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__acc_alignof)
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b) \
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(a) == sizeof(b))
|
||||
#else
|
||||
# define COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
# define __COMPILE_TIME_ASSERT_ALIGNOF(a,b) \
|
||||
__COMPILE_TIME_ASSERT_ALIGNOF_SIZEOF(a,b)
|
||||
#endif
|
||||
#define COMPILE_TIME_ASSERT_ALIGNED1(a) __COMPILE_TIME_ASSERT_ALIGNOF(a,char)
|
||||
|
||||
#define TABLESIZE(table) ((sizeof(table)/sizeof((table)[0])))
|
||||
|
||||
|
||||
#if 0
|
||||
#define ALIGN_DOWN(a,b) (((a) / (b)) * (b))
|
||||
#define ALIGN_UP(a,b) ALIGN_DOWN((a) + ((b) - 1), b)
|
||||
#define ALIGN_GAP(a,b) (ALIGN_UP(a,b) - (a))
|
||||
#elif 1
|
||||
template <class T>
|
||||
inline T ALIGN_DOWN(const T& a, const T& b) { T r; r = (a / b) * b; return r; }
|
||||
template <class T>
|
||||
inline T ALIGN_UP (const T& a, const T& b) { T r; r = ((a + b - 1) / b) * b; return r; }
|
||||
template <class T>
|
||||
inline T ALIGN_GAP (const T& a, const T& b) { T r; r = ALIGN_UP(a, b) - a; return r; }
|
||||
#else
|
||||
inline unsigned ALIGN_DOWN(unsigned a, unsigned b) { return (a / b) * b; }
|
||||
inline unsigned ALIGN_UP (unsigned a, unsigned b) { return ((a + b - 1) / b) * b; }
|
||||
inline unsigned ALIGN_GAP (unsigned a, unsigned b) { return ALIGN_UP(a, b) - a; }
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define UPX_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define UPX_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define UPX_MAX3(a,b,c) ((a) >= (b) ? UPX_MAX(a,c) : UPX_MAX(b,c))
|
||||
#define UPX_MIN3(a,b,c) ((a) <= (b) ? UPX_MIN(a,c) : UPX_MIN(b,c))
|
||||
|
||||
|
||||
#if 0 && defined(__cplusplus) && !defined(new) && !defined(delete)
|
||||
// global operators - debug
|
||||
inline void *operator new(size_t l)
|
||||
{
|
||||
void *p = malloc(l);
|
||||
printf("new %6ld %p\n",(long)l,p);
|
||||
fflush(stdout);
|
||||
return p;
|
||||
}
|
||||
inline void *operator new[](size_t l)
|
||||
{
|
||||
void *p = malloc(l);
|
||||
printf("new[] %6ld %p\n",(long)l,p);
|
||||
fflush(stdout);
|
||||
return p;
|
||||
}
|
||||
inline void operator delete(void *p)
|
||||
{
|
||||
printf("delete %p\n",p);
|
||||
fflush(stdout);
|
||||
if (p) free(p);
|
||||
}
|
||||
inline void operator delete[](void *p)
|
||||
{
|
||||
printf("delete[] %p\n",p);
|
||||
fflush(stdout);
|
||||
if (p) free(p);
|
||||
}
|
||||
#elif 1
|
||||
template <class T>
|
||||
inline const T& UPX_MAX(const T& a, const T& b) { if (a < b) return b; return a; }
|
||||
template <class T>
|
||||
inline const T& UPX_MIN(const T& a, const T& b) { if (a < b) return a; return b; }
|
||||
#else
|
||||
inline unsigned UPX_MAX(unsigned a, unsigned b) { return a < b ? b : a; }
|
||||
inline unsigned UPX_MIN(unsigned a, unsigned b) { return a < b ? a : b; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -477,6 +417,16 @@ inline void operator delete[](void *p)
|
||||
|
||||
#define ByteArray(var, size) Array(unsigned char, var, size)
|
||||
|
||||
struct noncopyable
|
||||
{
|
||||
protected:
|
||||
inline noncopyable() {}
|
||||
inline ~noncopyable() {}
|
||||
private:
|
||||
noncopyable(const noncopyable &); // undefined
|
||||
const noncopyable& operator=(const noncopyable &); // undefined
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// constants
|
||||
@@ -496,28 +446,23 @@ inline void operator delete[](void *p)
|
||||
#define EXIT_INTERNAL 1
|
||||
|
||||
|
||||
// compression methods - DO NOT CHANGE
|
||||
#define M_SKIP (-2)
|
||||
#define M_END (-1)
|
||||
#define M_NRV2B_LE32 2
|
||||
#define M_NRV2B_8 3
|
||||
#define M_NRV2B_LE16 4
|
||||
#define M_NRV2D_LE32 5
|
||||
#define M_NRV2D_8 6
|
||||
#define M_NRV2D_LE16 7
|
||||
#define M_NRV2E_LE32 8
|
||||
#define M_NRV2E_8 9
|
||||
#define M_NRV2E_LE16 10
|
||||
#define M_CL1B_LE32 11
|
||||
#define M_CL1B_8 12
|
||||
#define M_CL1B_LE16 13
|
||||
#define M_LZMA 14
|
||||
// magic constants for patching
|
||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||
#define UPX_MAGIC2_LE32 0xD5D0D8A1
|
||||
|
||||
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
|
||||
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
|
||||
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
|
||||
#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
|
||||
#define M_IS_LZMA(x) ((x) == M_LZMA)
|
||||
|
||||
// upx_compress() error codes
|
||||
#define UPX_E_OK (0)
|
||||
#define UPX_E_ERROR (-1)
|
||||
#define UPX_E_OUT_OF_MEMORY (-2)
|
||||
#define UPX_E_NOT_COMPRESSIBLE (-3)
|
||||
#define UPX_E_INPUT_OVERRUN (-4)
|
||||
#define UPX_E_OUTPUT_OVERRUN (-5)
|
||||
#define UPX_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define UPX_E_EOF_NOT_FOUND (-7)
|
||||
#define UPX_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define UPX_E_NOT_YET_IMPLEMENTED (-9)
|
||||
#define UPX_E_INVALID_ARGUMENT (-10)
|
||||
|
||||
|
||||
// Executable formats. Note: big endian types are >= 128.
|
||||
@@ -543,23 +488,258 @@ inline void operator delete[](void *p)
|
||||
#define UPX_F_LINUX_ELFI_i386 20
|
||||
#define UPX_F_WINCE_ARM_PE 21
|
||||
#define UPX_F_LINUX_ELF64_AMD 22
|
||||
#define UPX_F_LINUX_ELF32_ARMLE 23
|
||||
|
||||
#define UPX_F_LINUX_ELF32_ARMEL 23
|
||||
#define UPX_F_BSD_i386 24
|
||||
#define UPX_F_BSD_ELF_i386 25
|
||||
#define UPX_F_BSD_SH_i386 26
|
||||
|
||||
#define UPX_F_VMLINUX_AMD64 27
|
||||
#define UPX_F_VMLINUX_ARMEL 28
|
||||
#define UPX_F_MACH_i386 29
|
||||
#define UPX_F_LINUX_ELF32_MIPSEL 30
|
||||
#define UPX_F_VMLINUZ_ARMEL 31
|
||||
#define UPX_F_MACH_ARMEL 32
|
||||
|
||||
#define UPX_F_DYLIB_i386 33
|
||||
#define UPX_F_MACH_AMD64 34
|
||||
#define UPX_F_DYLIB_AMD64 35
|
||||
|
||||
#define UPX_F_WIN64_PEP 36
|
||||
|
||||
#define UPX_F_PLAIN_TEXT 127
|
||||
|
||||
#define UPX_F_ATARI_TOS 129
|
||||
#define UPX_F_SOLARIS_SPARC 130
|
||||
#define UPX_F_MACH_PPC32 131
|
||||
#define UPX_F_LINUX_ELFPPC32 132
|
||||
#define UPX_F_LINUX_ELF32_ARMBE 133
|
||||
#define UPX_F_LINUX_ELF32_ARMEB 133
|
||||
#define UPX_F_MACH_FAT 134
|
||||
#define UPX_F_VMLINUX_ARMEB 135
|
||||
#define UPX_F_VMLINUX_PPC32 136
|
||||
#define UPX_F_LINUX_ELF32_MIPSEB 137
|
||||
#define UPX_F_DYLIB_PPC32 138
|
||||
|
||||
|
||||
#define UPX_MAGIC_LE32 0x21585055 /* "UPX!" */
|
||||
#define UPX_MAGIC2_LE32 0xD5D0D8A1
|
||||
// compression methods
|
||||
#define M_ALL (-1)
|
||||
#define M_END (-2)
|
||||
#define M_NONE (-3)
|
||||
#define M_SKIP (-4)
|
||||
#define M_ULTRA_BRUTE (-5)
|
||||
// compression methods - DO NOT CHANGE
|
||||
#define M_NRV2B_LE32 2
|
||||
#define M_NRV2B_8 3
|
||||
#define M_NRV2B_LE16 4
|
||||
#define M_NRV2D_LE32 5
|
||||
#define M_NRV2D_8 6
|
||||
#define M_NRV2D_LE16 7
|
||||
#define M_NRV2E_LE32 8
|
||||
#define M_NRV2E_8 9
|
||||
#define M_NRV2E_LE16 10
|
||||
//#define M_CL1B_LE32 11
|
||||
//#define M_CL1B_8 12
|
||||
//#define M_CL1B_LE16 13
|
||||
#define M_LZMA 14
|
||||
#define M_DEFLATE 15 /* zlib */
|
||||
|
||||
#define M_IS_NRV2B(x) ((x) >= M_NRV2B_LE32 && (x) <= M_NRV2B_LE16)
|
||||
#define M_IS_NRV2D(x) ((x) >= M_NRV2D_LE32 && (x) <= M_NRV2D_LE16)
|
||||
#define M_IS_NRV2E(x) ((x) >= M_NRV2E_LE32 && (x) <= M_NRV2E_LE16)
|
||||
//#define M_IS_CL1B(x) ((x) >= M_CL1B_LE32 && (x) <= M_CL1B_LE16)
|
||||
#define M_IS_LZMA(x) (((x) & 255) == M_LZMA)
|
||||
#define M_IS_DEFLATE(x) ((x) == M_DEFLATE)
|
||||
|
||||
|
||||
// filters
|
||||
#define FT_END (-1)
|
||||
#define FT_NONE (-2)
|
||||
#define FT_SKIP (-3)
|
||||
#define FT_ULTRA_BRUTE (-4)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compression - callback_t
|
||||
**************************************************************************/
|
||||
|
||||
struct upx_callback_t;
|
||||
#define upx_callback_p upx_callback_t *
|
||||
#if 0
|
||||
typedef void* (__acc_cdecl *upx_alloc_func_t)
|
||||
(upx_callback_p self, unsigned items, unsigned size);
|
||||
typedef void (__acc_cdecl *upx_free_func_t)
|
||||
(upx_callback_p self, void* ptr);
|
||||
#endif
|
||||
typedef void (__acc_cdecl *upx_progress_func_t)
|
||||
(upx_callback_p, unsigned, unsigned);
|
||||
|
||||
struct upx_callback_t
|
||||
{
|
||||
upx_progress_func_t nprogress;
|
||||
void *user;
|
||||
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compression - config_t
|
||||
**************************************************************************/
|
||||
|
||||
template <class T, T default_value, T min_value, T max_value>
|
||||
struct OptVar
|
||||
{
|
||||
typedef T Type;
|
||||
static const T default_value_c = default_value;
|
||||
static const T min_value_c = min_value;
|
||||
static const T max_value_c = max_value;
|
||||
|
||||
void assertValue() {
|
||||
// FIXME: this generates annoying warnings "unsigned >= 0 is always true"
|
||||
//assert((v >= min_value) && (v <= max_value));
|
||||
}
|
||||
|
||||
OptVar() : v(default_value), is_set(0) { }
|
||||
OptVar& operator= (const T other) {
|
||||
v = other; is_set += 1;
|
||||
assertValue();
|
||||
return *this;
|
||||
}
|
||||
#if 0
|
||||
#error
|
||||
// there is too much implicit magic in this copy operator;
|
||||
// better introduce an explicit "oassign" function.
|
||||
OptVar& operator= (const OptVar& other) {
|
||||
if (other.is_set) { v = other.v; is_set += 1; }
|
||||
assertValue(); return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
void reset() { v = default_value; is_set = 0; }
|
||||
operator T () const { return v; }
|
||||
|
||||
T v;
|
||||
unsigned is_set;
|
||||
};
|
||||
|
||||
|
||||
// optional assignments
|
||||
template <class T> inline void oassign(T& self, const T& other) {
|
||||
if (other.is_set) { self.v = other.v; self.is_set += 1; }
|
||||
}
|
||||
#if 0
|
||||
template <class V, class T> inline void oassign(V& v, const T& other) {
|
||||
if (other.is_set) { v = other.v; }
|
||||
}
|
||||
#else
|
||||
template <class T> inline void oassign(unsigned& v, const T& other) {
|
||||
if (other.is_set) { v = other.v; }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct lzma_compress_config_t
|
||||
{
|
||||
typedef OptVar<unsigned, 2u, 0u, 4u> pos_bits_t; // pb
|
||||
typedef OptVar<unsigned, 0u, 0u, 4u> lit_pos_bits_t; // lb
|
||||
typedef OptVar<unsigned, 3u, 0u, 8u> lit_context_bits_t; // lc
|
||||
typedef OptVar<unsigned, (1u<<22), 1u, (1u<<30) > dict_size_t;
|
||||
typedef OptVar<unsigned, 64u, 5u, 273u> num_fast_bytes_t;
|
||||
|
||||
pos_bits_t pos_bits; // pb
|
||||
lit_pos_bits_t lit_pos_bits; // lp
|
||||
lit_context_bits_t lit_context_bits; // lc
|
||||
dict_size_t dict_size;
|
||||
unsigned fast_mode;
|
||||
num_fast_bytes_t num_fast_bytes;
|
||||
unsigned match_finder_cycles;
|
||||
|
||||
unsigned max_num_probs;
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
||||
struct ucl_compress_config_t : public REAL_ucl_compress_config_t
|
||||
{
|
||||
void reset() { memset(this, 0xff, sizeof(*this)); }
|
||||
};
|
||||
|
||||
|
||||
struct zlib_compress_config_t
|
||||
{
|
||||
typedef OptVar<unsigned, 8u, 1u, 9u> mem_level_t; // ml
|
||||
typedef OptVar<unsigned, 15u, 9u, 15u> window_bits_t; // wb
|
||||
typedef OptVar<unsigned, 0u, 0u, 4u> strategy_t; // st
|
||||
|
||||
mem_level_t mem_level; // ml
|
||||
window_bits_t window_bits; // wb
|
||||
strategy_t strategy; // st
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
||||
struct upx_compress_config_t
|
||||
{
|
||||
lzma_compress_config_t conf_lzma;
|
||||
ucl_compress_config_t conf_ucl;
|
||||
zlib_compress_config_t conf_zlib;
|
||||
void reset() { conf_lzma.reset(); conf_ucl.reset(); conf_zlib.reset(); }
|
||||
};
|
||||
|
||||
#define NULL_cconf ((upx_compress_config_t *) NULL)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// compression - result_t
|
||||
**************************************************************************/
|
||||
|
||||
struct lzma_compress_result_t
|
||||
{
|
||||
unsigned pos_bits; // pb
|
||||
unsigned lit_pos_bits; // lp
|
||||
unsigned lit_context_bits; // lc
|
||||
unsigned dict_size;
|
||||
unsigned fast_mode;
|
||||
unsigned num_fast_bytes;
|
||||
unsigned match_finder_cycles;
|
||||
unsigned num_probs; // (computed result)
|
||||
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
|
||||
struct ucl_compress_result_t
|
||||
{
|
||||
ucl_uint result[16];
|
||||
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
|
||||
struct zlib_compress_result_t
|
||||
{
|
||||
unsigned dummy;
|
||||
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
|
||||
struct upx_compress_result_t
|
||||
{
|
||||
// debug
|
||||
int method, level;
|
||||
unsigned u_len, c_len;
|
||||
|
||||
lzma_compress_result_t result_lzma;
|
||||
ucl_compress_result_t result_ucl;
|
||||
zlib_compress_result_t result_zlib;
|
||||
|
||||
void reset() {
|
||||
memset(this, 0, sizeof(*this));
|
||||
result_lzma.reset(); result_ucl.reset(); result_zlib.reset();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -585,9 +765,8 @@ typedef ElfLinker Linker;
|
||||
|
||||
// main.cpp
|
||||
extern const char *progname;
|
||||
void init_options(struct options_t *o);
|
||||
bool set_ec(int ec);
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void e_exit(int ec) __attribute__((__noreturn__));
|
||||
#else
|
||||
void e_exit(int ec);
|
||||
@@ -599,7 +778,7 @@ void printSetNl(int need_nl);
|
||||
void printClearLine(FILE *f = NULL);
|
||||
void printErr(const char *iname, const Throwable *e);
|
||||
void printUnhandledException(const char *iname, const std::exception *e);
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va printErr(const char *iname, const char *format, ...)
|
||||
__attribute__((__format__(__printf__,2,3)));
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...)
|
||||
@@ -609,7 +788,7 @@ void __acc_cdecl_va printErr(const char *iname, const char *format, ...);
|
||||
void __acc_cdecl_va printWarn(const char *iname, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if (ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
#if (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_LLVM || ACC_CC_PATHSCALE)
|
||||
void __acc_cdecl_va infoWarning(const char *format, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void __acc_cdecl_va infoHeader(const char *format, ...)
|
||||
@@ -632,7 +811,7 @@ void do_files(int i, int argc, char *argv[]);
|
||||
|
||||
// help.cpp
|
||||
void show_head(void);
|
||||
void show_help(int x = 0);
|
||||
void show_help(int verbose=0);
|
||||
void show_license(void);
|
||||
void show_usage(void);
|
||||
void show_version(int);
|
||||
@@ -652,8 +831,10 @@ int upx_decompress ( const upx_bytep src, unsigned src_len,
|
||||
upx_bytep dst, unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
int upx_test_overlap ( const upx_bytep buf, unsigned src_off,
|
||||
unsigned src_len, unsigned* dst_len,
|
||||
int upx_test_overlap ( const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned src_off, unsigned src_len,
|
||||
unsigned* dst_len,
|
||||
int method,
|
||||
const upx_compress_result_t *cresult );
|
||||
|
||||
|
||||
+22
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -39,41 +39,41 @@
|
||||
#undef USE_SCREEN_WIN32
|
||||
#undef USE_FRAMES
|
||||
|
||||
#if defined(WITH_GUI) && !defined(NO_CONSOLE)
|
||||
# define NO_CONSOLE
|
||||
#if 1 && (WITH_GUI) && !defined(NO_CONSOLE)
|
||||
# define NO_CONSOLE 1
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__linux__)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_VCSA
|
||||
# if !defined(HAVE_LINUX_KD_H)
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_VCSA 1
|
||||
# if !(HAVE_LINUX_KD_H)
|
||||
# undef USE_SCREEN
|
||||
# undef USE_SCREEN_VCSA
|
||||
# endif
|
||||
# if !defined(HAVE_LINUX_KDEV_T_H) || !defined(HAVE_LINUX_MAJOR_H)
|
||||
# if !(HAVE_LINUX_KDEV_T_H) || !(HAVE_LINUX_MAJOR_H)
|
||||
# undef USE_SCREEN
|
||||
# undef USE_SCREEN_VCSA
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 1 && defined(__DJGPP__)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN 1
|
||||
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_WIN32 1
|
||||
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
|
||||
# define USE_SCREEN
|
||||
# define USE_SCREEN_WIN32
|
||||
# define USE_SCREEN 1
|
||||
# define USE_SCREEN_WIN32 1
|
||||
#endif
|
||||
|
||||
|
||||
#if 0 || defined(NO_ANSI)
|
||||
#if 0 || (NO_ANSI)
|
||||
# undef USE_ANSI
|
||||
#endif
|
||||
#if 0 || defined(NO_SCREEN)
|
||||
#if 0 || (NO_SCREEN)
|
||||
# undef USE_SCREEN
|
||||
#endif
|
||||
#if 0 || defined(NO_FRAMES) || !defined(USE_SCREEN)
|
||||
#if 0 || (NO_FRAMES) || !(USE_SCREEN)
|
||||
# undef USE_FRAMES
|
||||
#endif
|
||||
#if 1
|
||||
@@ -81,11 +81,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if 0 || defined(USE_ANSI) || defined(USE_SCREEN)
|
||||
# define USE_CONSOLE
|
||||
#if 0 || (USE_ANSI) || (USE_SCREEN)
|
||||
# define USE_CONSOLE 1
|
||||
#endif
|
||||
|
||||
#if 0 || defined(NO_CONSOLE) || !defined(USE_CONSOLE)
|
||||
#if 0 || (NO_CONSOLE) || !(USE_CONSOLE)
|
||||
# undef USE_CONSOLE
|
||||
# undef USE_ANSI
|
||||
# undef USE_SCREEN
|
||||
@@ -110,7 +110,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -165,7 +165,7 @@ void __acc_cdecl_va con_fprintf(FILE *f, const char *format, ...);
|
||||
|
||||
extern FILE *con_term;
|
||||
|
||||
#if defined(USE_CONSOLE)
|
||||
#if (USE_CONSOLE)
|
||||
|
||||
extern int con_mode;
|
||||
extern console_t *con;
|
||||
|
||||
+20
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
long Throwable::counter = 0;
|
||||
unsigned long Throwable::counter = 0;
|
||||
|
||||
Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||
: super(), msg(NULL), err(e), is_warning(w)
|
||||
@@ -41,7 +41,7 @@ Throwable::Throwable(const char *m, int e, bool w) NOTHROW
|
||||
if (m)
|
||||
msg = strdup(m);
|
||||
#if 0
|
||||
fprintf(stderr, "construct exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "construct exception: %s %lu\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
@@ -53,7 +53,7 @@ Throwable::Throwable(const Throwable &other) NOTHROW
|
||||
if (other.msg)
|
||||
msg = strdup(other.msg);
|
||||
#if 0
|
||||
fprintf(stderr, "copy exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "copy exception: %s %lu\n", msg, counter);
|
||||
counter++;
|
||||
#endif
|
||||
}
|
||||
@@ -63,7 +63,7 @@ Throwable::~Throwable() NOTHROW
|
||||
{
|
||||
#if 0
|
||||
counter--;
|
||||
fprintf(stderr, "destruct exception: %s %ld\n", msg, counter);
|
||||
fprintf(stderr, "destruct exception: %s %lu\n", msg, counter);
|
||||
#endif
|
||||
if (msg)
|
||||
free(msg);
|
||||
@@ -85,6 +85,11 @@ void throwCantPack(const char *msg)
|
||||
throw CantUnpackException(msg);
|
||||
}
|
||||
|
||||
void throwCantPackExact()
|
||||
{
|
||||
throwCantPack("option '--exact' does not work with this file");
|
||||
}
|
||||
|
||||
void throwFilterException()
|
||||
{
|
||||
throwCantPack("filter problem");
|
||||
@@ -156,6 +161,14 @@ void throwBadLoader()
|
||||
}
|
||||
|
||||
|
||||
void throwOutOfMemoryException(const char *msg)
|
||||
{
|
||||
if (msg == NULL)
|
||||
msg = "out of memory";
|
||||
throw OutOfMemoryException(msg);
|
||||
}
|
||||
|
||||
|
||||
void throwIOException(const char *msg, int e)
|
||||
{
|
||||
throw IOException(msg, e);
|
||||
|
||||
+8
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_EXCEPT_H
|
||||
#define __UPX_EXCEPT_H
|
||||
#define __UPX_EXCEPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
DISABLE_NEW_DELETE
|
||||
|
||||
private:
|
||||
static long counter; // for debugging
|
||||
static unsigned long counter; // for debugging
|
||||
};
|
||||
|
||||
|
||||
@@ -204,10 +204,11 @@ public:
|
||||
// (noreturn) is probably not the correct semantics for throwing exceptions
|
||||
#define NORET __attribute__((__noreturn__))
|
||||
#else
|
||||
#define NORET
|
||||
#define NORET /*empty*/
|
||||
#endif
|
||||
|
||||
void throwCantPack(const char *msg) NORET;
|
||||
void throwCantPackExact() NORET;
|
||||
void throwUnknownExecutableFormat(const char *msg = NULL, bool warn = false) NORET;
|
||||
void throwNotCompressible(const char *msg = NULL) NORET;
|
||||
void throwAlreadyPacked(const char *msg = NULL) NORET;
|
||||
@@ -219,6 +220,7 @@ void throwBadLoader() NORET;
|
||||
void throwChecksumError() NORET;
|
||||
void throwCompressedDataViolation() NORET;
|
||||
void throwInternalError(const char *msg) NORET;
|
||||
void throwOutOfMemoryException(const char *msg = NULL) NORET;
|
||||
void throwIOException(const char *msg = NULL, int e = 0) NORET;
|
||||
void throwEOFException(const char *msg = NULL, int e = 0) NORET;
|
||||
|
||||
|
||||
+115
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
void File::chmod(const char *name, int mode)
|
||||
{
|
||||
#if defined(HAVE_CHMOD)
|
||||
#if (HAVE_CHMOD)
|
||||
if (::chmod(name,mode) != 0)
|
||||
throwIOException(name,errno);
|
||||
#else
|
||||
@@ -69,7 +69,7 @@ void File::unlink(const char *name)
|
||||
**************************************************************************/
|
||||
|
||||
FileBase::FileBase() :
|
||||
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL)
|
||||
_fd(-1), _flags(0), _shflags(0), _mode(0), _name(NULL), _offset(0), _length(0)
|
||||
{
|
||||
memset(&st,0,sizeof(st));
|
||||
}
|
||||
@@ -88,7 +88,7 @@ FileBase::~FileBase()
|
||||
}
|
||||
|
||||
|
||||
void FileBase::sopen()
|
||||
bool FileBase::do_sopen()
|
||||
{
|
||||
if (_shflags < 0)
|
||||
_fd = ::open(_name, _flags, _mode);
|
||||
@@ -101,9 +101,15 @@ void FileBase::sopen()
|
||||
#elif defined(SH_DENYRW)
|
||||
_fd = ::sopen(_name, _flags, _shflags, _mode);
|
||||
#else
|
||||
assert(0);
|
||||
throwInternalError("bad usage of do_sopen()");
|
||||
#endif
|
||||
}
|
||||
if (_fd < 0)
|
||||
return false;
|
||||
if (::fstat(_fd, &st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
_length = st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +123,8 @@ bool FileBase::close()
|
||||
_flags = 0;
|
||||
_mode = 0;
|
||||
_name = NULL;
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -164,10 +172,17 @@ void FileBase::seek(off_t off, int whence)
|
||||
{
|
||||
if (!isOpen())
|
||||
throwIOException("bad seek 1");
|
||||
if (whence == SEEK_SET && off < 0)
|
||||
throwIOException("bad seek 2");
|
||||
if (whence == SEEK_END && off > 0)
|
||||
throwIOException("bad seek 3");
|
||||
if (whence == SEEK_SET) {
|
||||
if (off < 0)
|
||||
throwIOException("bad seek 2");
|
||||
off += _offset;
|
||||
}
|
||||
if (whence == SEEK_END) {
|
||||
if (off > 0)
|
||||
throwIOException("bad seek 3");
|
||||
off += _offset + _length;
|
||||
whence = SEEK_SET;
|
||||
}
|
||||
if (::lseek(_fd,off,whence) < 0)
|
||||
throwIOException("seek error",errno);
|
||||
}
|
||||
@@ -180,7 +195,19 @@ off_t FileBase::tell() const
|
||||
off_t l = ::lseek(_fd, 0, SEEK_CUR);
|
||||
if (l < 0)
|
||||
throwIOException("tell error",errno);
|
||||
return l;
|
||||
return l - _offset;
|
||||
}
|
||||
|
||||
|
||||
void FileBase::set_extent(off_t offset, off_t length)
|
||||
{
|
||||
_offset = offset;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
off_t FileBase::st_size() const
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,8 +232,9 @@ void InputFile::sopen(const char *name, int flags, int shflags)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = 0;
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (!FileBase::do_sopen())
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
throw FileNotFoundException(_name, errno);
|
||||
@@ -289,8 +317,9 @@ void OutputFile::sopen(const char *name, int flags, int shflags, int mode)
|
||||
_flags = flags;
|
||||
_shflags = shflags;
|
||||
_mode = mode;
|
||||
FileBase::sopen();
|
||||
if (!isOpen())
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (!FileBase::do_sopen())
|
||||
{
|
||||
#if 0
|
||||
// don't throw FileNotFound here -- this is confusing
|
||||
@@ -316,6 +345,8 @@ bool OutputFile::openStdout(int flags, bool force)
|
||||
_flags = flags;
|
||||
_shflags = -1;
|
||||
_mode = 0;
|
||||
_offset = 0;
|
||||
_length = 0;
|
||||
if (flags && acc_set_binmode(fd, 1) == -1)
|
||||
throwIOException(_name, errno);
|
||||
_fd = fd;
|
||||
@@ -329,6 +360,18 @@ void OutputFile::write(const void *buf, int len)
|
||||
bytes_written += len;
|
||||
}
|
||||
|
||||
off_t OutputFile::st_size() const
|
||||
{
|
||||
if (opt->to_stdout) { // might be a pipe ==> .st_size is invalid
|
||||
return bytes_written; // too big if seek()+write() instead of rewrite()
|
||||
}
|
||||
struct stat my_st;
|
||||
my_st.st_size = 0;
|
||||
if (::fstat(_fd, &my_st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
return my_st.st_size;
|
||||
}
|
||||
|
||||
|
||||
void OutputFile::write(const MemBuffer *buf, int len)
|
||||
{
|
||||
@@ -343,6 +386,62 @@ void OutputFile::write(const MemBuffer &buf, int len)
|
||||
write(&buf, len);
|
||||
}
|
||||
|
||||
void OutputFile::rewrite(const void *buf, int len)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
|
||||
void OutputFile::seek(off_t off, int whence)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
switch (whence) {
|
||||
case SEEK_SET: {
|
||||
if (bytes_written < off) {
|
||||
bytes_written = off;
|
||||
}
|
||||
_length = bytes_written; // cheap, lazy update; needed?
|
||||
} break;
|
||||
case SEEK_END: {
|
||||
_length = bytes_written; // necessary
|
||||
} break;
|
||||
}
|
||||
super::seek(off,whence);
|
||||
}
|
||||
|
||||
// WARNING: fsync() does not exist in some Windows environments.
|
||||
// This trick works only on UNIX-like systems.
|
||||
//int OutputFile::read(void *buf, int len)
|
||||
//{
|
||||
// fsync(_fd);
|
||||
// InputFile infile;
|
||||
// infile.open(this->getName(), O_RDONLY);
|
||||
// infile.seek(this->tell(), SEEK_SET);
|
||||
// return infile.read(buf, len);
|
||||
//}
|
||||
|
||||
void OutputFile::set_extent(off_t offset, off_t length)
|
||||
{
|
||||
super::set_extent(offset, length);
|
||||
bytes_written = 0;
|
||||
if (0==offset && (off_t)~0u==length) {
|
||||
if (::fstat(_fd, &st) != 0)
|
||||
throwIOException(_name, errno);
|
||||
_length = st.st_size - offset;
|
||||
}
|
||||
}
|
||||
|
||||
off_t OutputFile::unset_extent()
|
||||
{
|
||||
off_t l = ::lseek(_fd, 0, SEEK_END);
|
||||
if (l < 0)
|
||||
throwIOException("lseek error", errno);
|
||||
_offset = 0;
|
||||
_length = l;
|
||||
bytes_written = _length;
|
||||
return _length;
|
||||
}
|
||||
|
||||
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||
{
|
||||
|
||||
+15
-17
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_FILE_H
|
||||
#define __UPX_FILE_H
|
||||
#define __UPX_FILE_H 1
|
||||
|
||||
class MemBuffer;
|
||||
|
||||
@@ -59,9 +59,11 @@ public:
|
||||
virtual bool isOpen() const { return _fd >= 0; }
|
||||
int getFd() const { return _fd; }
|
||||
const char *getName() const { return _name; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
|
||||
protected:
|
||||
void sopen();
|
||||
bool do_sopen();
|
||||
virtual int read(void *buf, int len);
|
||||
virtual int readx(void *buf, int len);
|
||||
virtual void write(const void *buf, int len);
|
||||
@@ -73,6 +75,8 @@ protected:
|
||||
int _shflags;
|
||||
int _mode;
|
||||
const char *_name;
|
||||
off_t _offset;
|
||||
off_t _length;
|
||||
public:
|
||||
struct stat st;
|
||||
};
|
||||
@@ -128,21 +132,15 @@ public:
|
||||
virtual void write(const void *buf, int len);
|
||||
virtual void write(const MemBuffer *buf, int len);
|
||||
virtual void write(const MemBuffer &buf, int len);
|
||||
virtual void set_extent(off_t offset, off_t length);
|
||||
virtual off_t unset_extent(); // returns actual length
|
||||
|
||||
off_t getBytesWritten() const { return bytes_written; }
|
||||
virtual off_t st_size() const; // { return _length; }
|
||||
|
||||
// FIXME - these won't work when using the `--stdout' option
|
||||
virtual void seek(off_t off, int whence)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
super::seek(off,whence);
|
||||
}
|
||||
virtual void rewrite(const void *buf, int len)
|
||||
{
|
||||
assert(!opt->to_stdout);
|
||||
write(buf, len);
|
||||
bytes_written -= len; // restore
|
||||
}
|
||||
// FIXME - these won't work when using the '--stdout' option
|
||||
virtual void seek(off_t off, int whence);
|
||||
virtual void rewrite(const void *buf, int len);
|
||||
|
||||
// util
|
||||
static void dump(const char *name, const void *buf, int len, int flags=-1);
|
||||
|
||||
+21
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -61,10 +61,10 @@ const FilterImp::FilterEntry *FilterImp::getFilter(int id)
|
||||
memset(filter_map, 0xff, sizeof(filter_map));
|
||||
for (int i = 0; i < n_filters; i++)
|
||||
{
|
||||
int fid = filters[i].id;
|
||||
assert(fid >= 0 && fid <= 255);
|
||||
assert(filter_map[fid] == 0xff);
|
||||
filter_map[fid] = (unsigned char) i;
|
||||
int filter_id = filters[i].id;
|
||||
assert(filter_id >= 0 && filter_id <= 255);
|
||||
assert(filter_map[filter_id] == 0xff);
|
||||
filter_map[filter_id] = (unsigned char) i;
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
@@ -85,6 +85,20 @@ bool Filter::isValidFilter(int filter_id)
|
||||
return fe != NULL;
|
||||
}
|
||||
|
||||
bool Filter::isValidFilter(int filter_id, const int *allowed_filters)
|
||||
{
|
||||
if (!isValidFilter(filter_id))
|
||||
return false;
|
||||
if (filter_id == 0)
|
||||
return true;
|
||||
if (allowed_filters == NULL)
|
||||
return false;
|
||||
while (*allowed_filters != FT_END)
|
||||
if (*allowed_filters++ == filter_id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// high level API
|
||||
|
||||
+6
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_FILTER_H
|
||||
#define __UPX_FILTER_H
|
||||
#define __UPX_FILTER_H 1
|
||||
|
||||
class Filter;
|
||||
class FilterImp;
|
||||
@@ -62,6 +62,7 @@ public:
|
||||
bool scan(const upx_byte *buf, unsigned buf_len);
|
||||
|
||||
static bool isValidFilter(int filter_id);
|
||||
static bool isValidFilter(int filter_id, const int *allowed_filters);
|
||||
|
||||
public:
|
||||
// Will be set by each call to filter()/unfilter().
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+16
-9
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
@@ -58,10 +58,18 @@ static int F(Filter *f)
|
||||
// must not conflict with the mark.
|
||||
// Note that unsigned comparison checks both edges of buffer.
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
@@ -79,8 +87,7 @@ static int F(Filter *f)
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
@@ -119,7 +126,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+17
-10
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -51,16 +51,24 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic,lastcall))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
@@ -78,8 +86,7 @@ static int F(Filter *f)
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
@@ -118,7 +125,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+8
-8
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -123,8 +123,8 @@ static int F(Filter *f)
|
||||
N_MRU : 0;
|
||||
#endif //}
|
||||
|
||||
// FIXME: We must fit into 8MB because we steal one bit.
|
||||
// find a 16MB large empty address space
|
||||
// FIXME: We must fit into 8 MiB because we steal one bit.
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
int which;
|
||||
unsigned char buf[256];
|
||||
@@ -249,11 +249,11 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
/*#ifdef TESTING*/
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,noncalls2,size,cto8);
|
||||
printf("CALL/JMP/JCC %d %d %d\n",wtally[0],wtally[1],wtally[2]);
|
||||
/*#endif*/
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -52,16 +52,24 @@ static int F(Filter *f)
|
||||
unsigned calls = 0, noncalls = 0, noncalls2 = 0;
|
||||
unsigned lastnoncall = size, lastcall = 0;
|
||||
|
||||
// find a 16MB large empty address space
|
||||
// find a 16 MiB large empty address space
|
||||
{
|
||||
unsigned char buf[256];
|
||||
memset(buf,0,256);
|
||||
|
||||
for (ic = 0; ic < size - 5; ic++)
|
||||
if (COND(b,ic,lastcall,id) && get_le32(b+ic+1)+ic+1 >= size)
|
||||
{
|
||||
if (!COND(b,ic,lastcall,id))
|
||||
continue;
|
||||
jc = get_le32(b+ic+1)+ic+1;
|
||||
if (jc < size)
|
||||
{
|
||||
buf[b[ic+1]] |= 1;
|
||||
if (jc + addvalue >= (1u << 24)) // hi 8 bits won't be cto8
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
buf[b[ic+1]] |= 1;
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0)
|
||||
return -1;
|
||||
@@ -79,8 +87,7 @@ static int F(Filter *f)
|
||||
// try to detect 'real' calls only
|
||||
if (jc < size)
|
||||
{
|
||||
if ((1u<<24)<=(jc+addvalue)) // hi 8 bits won't be cto8
|
||||
return 1; // fail - buffer not restored
|
||||
assert(jc + addvalue < (1u << 24)); // hi 8 bits won't be cto8
|
||||
#ifdef U
|
||||
set_be32(b+ic+1,jc+addvalue+cto);
|
||||
#endif
|
||||
@@ -119,7 +126,7 @@ static int F(Filter *f)
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
|
||||
#ifdef TESTING
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d noncalls2=%d text_size=%x calltrickoffset=%x\n",calls,noncalls,noncalls2,size,cto);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+17
-13
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2004-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2004-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -47,7 +47,7 @@ static int F(Filter *f)
|
||||
// scan
|
||||
const upx_byte *b = f->buf;
|
||||
#endif
|
||||
const unsigned size = umin(f->buf_len, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size = umin(f->buf_len, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = size -4;
|
||||
|
||||
unsigned ic;
|
||||
@@ -58,7 +58,7 @@ static int F(Filter *f)
|
||||
{
|
||||
unsigned char buf[256];
|
||||
unsigned short wbuf[256];
|
||||
const size_t WW = (size_t)0 - (~(size_t)0) << W_CTO; // ???
|
||||
const size_t WW = (size_t)0 - ((~(size_t)0) << W_CTO); // ???
|
||||
memset(wbuf, 0, sizeof(wbuf));
|
||||
memset(buf , 0, WW);
|
||||
memset(buf + WW, 1, 256 - WW);
|
||||
@@ -72,9 +72,11 @@ static int F(Filter *f)
|
||||
}
|
||||
|
||||
if (getcto(f, buf) < 0) {
|
||||
if (0!=W_CTO) // FIXME: what is this ???
|
||||
return -1;
|
||||
#if (W_CTO != 0)
|
||||
return -1;
|
||||
#else
|
||||
f->cto = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
const unsigned char cto8 = f->cto;
|
||||
@@ -95,8 +97,9 @@ static int F(Filter *f)
|
||||
lastcall = ic;
|
||||
}
|
||||
else {
|
||||
assert(0==W_CTO // FIXME: what is this ???
|
||||
|| (~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != cto8); // this should not happen
|
||||
#if (W_CTO != 0)
|
||||
assert((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) != (unsigned) cto8); // this should not happen
|
||||
#endif
|
||||
lastnoncall = ic;
|
||||
noncalls++;
|
||||
}
|
||||
@@ -105,8 +108,9 @@ static int F(Filter *f)
|
||||
f->calls = calls;
|
||||
f->noncalls = noncalls;
|
||||
f->lastcall = lastcall;
|
||||
ACC_UNUSED(lastnoncall);
|
||||
|
||||
#if 0
|
||||
#if 0 || defined(TESTING)
|
||||
printf("\ncalls=%d noncalls=%d text_size=%x calltrickoffset=%x\n",
|
||||
calls,noncalls,size,cto8);
|
||||
#endif
|
||||
@@ -122,14 +126,14 @@ static int F(Filter *f)
|
||||
static int U(Filter *f)
|
||||
{
|
||||
upx_byte *b = f->buf;
|
||||
const unsigned size4 = umin(f->buf_len - 4, -(~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned size4 = umin(f->buf_len - 4, 0u - (~0u<<(32 - (6+ W_CTO))));
|
||||
const unsigned addvalue = f->addvalue;
|
||||
|
||||
unsigned ic;
|
||||
|
||||
for (ic = 0; ic<=size4; ic+=4) if (COND(b,ic)) {
|
||||
unsigned const word = get_be32(b+ic);
|
||||
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == f->cto) {
|
||||
if ((~(~0u<<W_CTO) & (word>>(24+2 - W_CTO))) == (unsigned) f->cto) {
|
||||
unsigned const jc = word & (~(~0u<<(26 - W_CTO)) & (~0u<<2));
|
||||
set_be32(b+ic, (0xfc000003&word)|(0x03fffffc&(jc-ic-addvalue)));
|
||||
f->calls++;
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+5
-5
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ umin(unsigned const a, unsigned const b)
|
||||
|
||||
#define COND1(b,x) (b[x] == 0xe8 || b[x] == 0xe9)
|
||||
#define COND2(b,x,lc) (lc!=(x) && 0xf==b[(x)-1] && 0x80<=b[x] && b[x]<=0x8f)
|
||||
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
|
||||
#define COND(b,x,lc,id) (COND1(b,x) || ((9<=(0xf&(id))) && COND2(b,x,lc)))
|
||||
#define F f_ctok32_e8e9_bswap_le
|
||||
#define U u_ctok32_e8e9_bswap_le
|
||||
#include "filter/ctok.h"
|
||||
|
||||
+154
-99
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,11 +22,14 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "compress.h"
|
||||
#include "packmast.h"
|
||||
#include "packer.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -48,8 +51,9 @@ void show_head(void)
|
||||
fg = con_fg(f,FG_GREEN);
|
||||
con_fprintf(f,
|
||||
" Ultimate Packer for eXecutables\n"
|
||||
" Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006\n"
|
||||
" Copyright (C) 1996 - %s\n"
|
||||
"UPX %-10s Markus Oberhumer, Laszlo Molnar & John Reiser %14s\n\n",
|
||||
UPX_VERSION_YEAR,
|
||||
#if (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||
V("d"),
|
||||
#elif (ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||
@@ -88,7 +92,79 @@ void show_usage(void)
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
void show_help(int x)
|
||||
struct PackerNames
|
||||
{
|
||||
struct Entry {
|
||||
const char* fname;
|
||||
const char* sname;
|
||||
};
|
||||
Entry names[64];
|
||||
size_t names_count;
|
||||
const options_t *o;
|
||||
PackerNames() : names_count(0), o(NULL) { }
|
||||
void add(const Packer *p)
|
||||
{
|
||||
p->assertPacker();
|
||||
assert(names_count < 64);
|
||||
names[names_count].fname = p->getFullName(o);
|
||||
names[names_count].sname = p->getName();
|
||||
names_count++;
|
||||
}
|
||||
static Packer* visit(Packer *p, void *user)
|
||||
{
|
||||
PackerNames *self = (PackerNames *) user;
|
||||
self->add(p);
|
||||
delete p; p = NULL;
|
||||
return NULL;
|
||||
}
|
||||
static int __acc_cdecl_qsort cmp_fname(const void *a, const void *b) {
|
||||
return strcmp(((const Entry *) a)->fname, ((const Entry *) b)->fname);
|
||||
}
|
||||
static int __acc_cdecl_qsort cmp_sname(const void *a, const void *b) {
|
||||
return strcmp(((const Entry *) a)->sname, ((const Entry *) b)->sname);
|
||||
}
|
||||
};
|
||||
|
||||
static void show_all_packers(FILE *f, int verbose)
|
||||
{
|
||||
options_t o; o.reset();
|
||||
PackerNames pn; pn.o = &o;
|
||||
PackMaster::visitAllPackers(pn.visit, NULL, &o, &pn);
|
||||
qsort(pn.names, pn.names_count, sizeof(PackerNames::Entry), pn.cmp_fname);
|
||||
size_t pos = 0;
|
||||
for (size_t i = 0; i < pn.names_count; ++i)
|
||||
{
|
||||
const char *fn = pn.names[i].fname;
|
||||
const char *sn = pn.names[i].sname;
|
||||
if (verbose)
|
||||
{
|
||||
con_fprintf(f, " %-32s %s\n", fn, sn);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t fl = strlen(fn);
|
||||
if (pos == 0) {
|
||||
con_fprintf(f, " %s", fn);
|
||||
pos = 2 + fl;
|
||||
} else if (pos + 1 + fl > 80) {
|
||||
con_fprintf(f, "\n %s", fn);
|
||||
pos = 2 + fl;
|
||||
} else {
|
||||
con_fprintf(f, " %s", fn);
|
||||
pos += 1 + fl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!verbose && pn.names_count)
|
||||
con_fprintf(f, "\n");
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
void show_help(int verbose)
|
||||
{
|
||||
FILE *f = con_term;
|
||||
int fg;
|
||||
@@ -105,8 +181,8 @@ void show_help(int x)
|
||||
" -d decompress -l list compressed file\n"
|
||||
" -t test compressed file -V display version number\n"
|
||||
" -h give %s help -L display software license\n%s",
|
||||
x == 0 ? "" : " --best compress best (can be slow for big files)\n",
|
||||
x == 0 ? "more" : "this", x == 0 ? "" : "\n");
|
||||
verbose == 0 ? "" : " --best compress best (can be slow for big files)\n",
|
||||
verbose == 0 ? "more" : "this", verbose == 0 ? "" : "\n");
|
||||
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options:\n");
|
||||
@@ -114,22 +190,29 @@ void show_help(int x)
|
||||
|
||||
con_fprintf(f,
|
||||
" -q be quiet -v be verbose\n"
|
||||
" -oFILE write output to `FILE'\n"
|
||||
" -oFILE write output to 'FILE'\n"
|
||||
//" -f force overwrite of output files and compression of suspicious files\n"
|
||||
" -f force compression of suspicious files\n"
|
||||
"%s%s"
|
||||
, (x == 0) ? " -k keep backup files\n" : ""
|
||||
, (verbose == 0) ? " -k keep backup files\n" : ""
|
||||
#if 1
|
||||
, (x > 0) ? " --no-color, --mono, --color, --no-progress change look\n" : ""
|
||||
, (verbose > 0) ? " --no-color, --mono, --color, --no-progress change look\n" : ""
|
||||
#else
|
||||
, ""
|
||||
#endif
|
||||
);
|
||||
|
||||
if (x > 0)
|
||||
if (verbose > 0)
|
||||
{
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"\nBackup options:\n");
|
||||
con_fprintf(f,"\nCompression tuning options:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --brute try all available compression methods & filters [slow]\n"
|
||||
" --ultra-brute try even more compression variants [very slow]\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Backup options:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" -k, --backup keep backup files\n"
|
||||
@@ -144,26 +227,16 @@ void show_help(int x)
|
||||
" --overlay=skip don't compress a file with an overlay\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for atari/tos:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for djgpp2/coff:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --coff produce COFF output [default: EXE]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/com:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed com work on any 8086\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/exe:\n");
|
||||
@@ -171,15 +244,12 @@ void show_help(int x)
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed exe work on any 8086\n"
|
||||
" --no-reloc put no relocations in to the exe header\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for dos/sys:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --8086 make compressed sys work on any 8086\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
#if 0
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
@@ -194,34 +264,19 @@ void show_help(int x)
|
||||
con_fprintf(f,"Options for ps1/exe:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --8-bit uses 8 bit size compression [default: 32 bit]\n"
|
||||
" --8mb-ram 8 megabyte memory limit [default: 2 mb]\n"
|
||||
" --8mib-ram 8 megabyte memory limit [default: 2 MiB]\n"
|
||||
" --boot-only disables client/host transfer compatibility\n"
|
||||
" --no-align don't align to 2048 bytes [enables: --console-run]\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for tmt/adam:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for vmlinuz/386\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for watcom/le:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --le produce LE output [default: EXE]\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"Options for win32/pe & rtm32/pe:\n");
|
||||
con_fprintf(f,"Options for win32/pe, rtm32/pe & arm/pe:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --compress-exports=0 do not compress the export section\n"
|
||||
@@ -229,60 +284,44 @@ void show_help(int x)
|
||||
" --compress-icons=0 do not compress any icons\n"
|
||||
" --compress-icons=1 compress all but the first icon\n"
|
||||
" --compress-icons=2 compress all but the first icon directory [default]\n"
|
||||
" --compress-icons=3 compress all icons\n"
|
||||
" --compress-resources=0 do not compress any resources at all\n"
|
||||
" --keep-resource=list do not compress resources specified by list\n"
|
||||
" --strip-relocs=0 do not strip relocations\n"
|
||||
" --strip-relocs=1 strip relocations [default]\n"
|
||||
" --all-methods try all available compression methods\n"
|
||||
" --all-filters try all available preprocessing filters\n"
|
||||
"\n");
|
||||
con_fprintf(f,"Options for linux/elf:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f,
|
||||
" --preserve-build-id copy .gnu.note.build-id to compressed output\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
con_fprintf(f,
|
||||
"file.. executables to (de)compress\n"
|
||||
"\n");
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"This version supports:\n");
|
||||
fg = con_fg(f,fg);
|
||||
con_fprintf(f," "
|
||||
// TODO:
|
||||
// support for mach/ppc32
|
||||
// support for linux elf/ppc32
|
||||
// support for linux elf/amd64
|
||||
" arm/pe,"
|
||||
" atari/tos,"
|
||||
" bvmlinuz/386,"
|
||||
" djgpp2/coff,"
|
||||
" dos/com,"
|
||||
" dos/exe,"
|
||||
" dos/sys,"
|
||||
"\n "
|
||||
//" elks/8086,"
|
||||
" linux/amd64,"
|
||||
" linux/i386,"
|
||||
" linux/ppc32,"
|
||||
" mach/ppc32,"
|
||||
" ps1/exe,"
|
||||
" rtm32/pe,"
|
||||
"\n "
|
||||
" tmt/adam,"
|
||||
" vmlinux/386,"
|
||||
" vmlinuz/386,"
|
||||
" watcom/le,"
|
||||
//" win16/ne,"
|
||||
" win32/pe"
|
||||
"\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n"
|
||||
// "\n\nUPX comes with ABSOLUTELY NO WARRANTY; for details type `upx -L'.\n"
|
||||
con_fprintf(f, "file.. executables to (de)compress\n");
|
||||
|
||||
if (verbose > 0)
|
||||
{
|
||||
fg = con_fg(f,FG_YELLOW);
|
||||
con_fprintf(f,"\nThis version supports:\n");
|
||||
fg = con_fg(f,fg);
|
||||
show_all_packers(f, verbose);
|
||||
}
|
||||
else
|
||||
{
|
||||
con_fprintf(f,"\nType '%s --help' for more detailed help.\n", progname);
|
||||
}
|
||||
|
||||
con_fprintf(f,"\nUPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net\n"
|
||||
// "\nUPX comes with ABSOLUTELY NO WARRANTY; for details type 'upx -L'.\n"
|
||||
"");
|
||||
|
||||
|
||||
#if defined(DEBUG) || defined(TESTING)
|
||||
#if (DEBUG) || (TESTING)
|
||||
fg = con_fg(f,FG_RED);
|
||||
con_fprintf(f,"\nWARNING: this version is compiled with"
|
||||
#if defined(DEBUG)
|
||||
#if (DEBUG)
|
||||
" -DDEBUG"
|
||||
#endif
|
||||
#if defined(TESTING)
|
||||
#if (TESTING)
|
||||
" -DTESTING"
|
||||
#endif
|
||||
"\n");
|
||||
@@ -326,7 +365,7 @@ void show_license(void)
|
||||
con_fprintf(f,
|
||||
"\n"
|
||||
" Markus F.X.J. Oberhumer Laszlo Molnar\n"
|
||||
" <mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>\n"
|
||||
" <markus@oberhumer.com> <ml1050@users.sourceforge.net>\n"
|
||||
);
|
||||
fg = con_fg(f,fg);
|
||||
|
||||
@@ -340,27 +379,43 @@ void show_license(void)
|
||||
|
||||
void show_version(int x)
|
||||
{
|
||||
FILE *f = stdout;
|
||||
FILE *fp = stdout;
|
||||
const char *v;
|
||||
UNUSED(x);
|
||||
UNUSED(v);
|
||||
|
||||
fprintf(f,"upx %s\n", UPX_VERSION_STRING);
|
||||
#if defined(WITH_NRV)
|
||||
fprintf(f,"NRV data compression library %s\n", nrv_version_string());
|
||||
fprintf(fp, "upx %s\n", UPX_VERSION_STRING);
|
||||
#if (WITH_NRV)
|
||||
v = upx_nrv_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "NRV data compression library %s\n", v);
|
||||
#endif
|
||||
#if defined(WITH_UCL)
|
||||
fprintf(f,"UCL data compression library %s\n", ucl_version_string());
|
||||
#if (WITH_UCL)
|
||||
v = upx_ucl_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "UCL data compression library %s\n", v);
|
||||
#endif
|
||||
#if 0 && defined(WITH_LZMA)
|
||||
fprintf(f,"LZMA SDK version ???\n");
|
||||
#if (WITH_ZLIB)
|
||||
v = upx_zlib_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "zlib data compression library %s\n", v);
|
||||
#endif
|
||||
fprintf(f,"Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f,"Copyright (C) 1996-2006 Laszlo Molnar\n");
|
||||
fprintf(f,"Copyright (C) 2000-2006 John F. Reiser\n");
|
||||
fprintf(f,"Copyright (C) 2002-2006 Jens Medoch\n");
|
||||
#if defined(WITH_LZMA)
|
||||
fprintf(f,"Copyright (C) 1999-2006 Igor Pavlov\n");
|
||||
#if (WITH_LZMA)
|
||||
v = upx_lzma_version_string();
|
||||
if (v != NULL && v[0])
|
||||
fprintf(fp, "LZMA SDK version %s\n", v);
|
||||
#endif
|
||||
fprintf(f,"UPX comes with ABSOLUTELY NO WARRANTY; for details type `%s -L'.\n", progname);
|
||||
fprintf(fp, "Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(fp, "Copyright (C) 1996-2013 Laszlo Molnar\n");
|
||||
fprintf(fp, "Copyright (C) 2000-2013 John F. Reiser\n");
|
||||
fprintf(fp, "Copyright (C) 2002-2013 Jens Medoch\n");
|
||||
#if (WITH_ZLIB)
|
||||
fprintf(fp, "Copyright (C) 1995" "-2005 Jean-loup Gailly and Mark Adler\n");
|
||||
#endif
|
||||
#if (WITH_LZMA)
|
||||
fprintf(fp, "Copyright (C) 1999" "-2006 Igor Pavlov\n");
|
||||
#endif
|
||||
fprintf(fp, "UPX comes with ABSOLUTELY NO WARRANTY; for details type '%s -L'.\n", progname);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+11
-16
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_LEFILE_H
|
||||
#define __UPX_LEFILE_H
|
||||
#define __UPX_LEFILE_H 1
|
||||
|
||||
class InputFile;
|
||||
class OutputFile;
|
||||
@@ -49,8 +49,8 @@ public:
|
||||
protected:
|
||||
enum { FIXUP_EXTRA = 3 };
|
||||
|
||||
struct le_header_t
|
||||
{ // 0x00
|
||||
__packed_struct(le_header_t)
|
||||
// 0x00
|
||||
char _[2]; // signature: 'LE' || 'LX'
|
||||
char byte_order; // 0 little endian
|
||||
char word_order; // 0 little endian
|
||||
@@ -117,28 +117,23 @@ protected:
|
||||
LE16 device_id;
|
||||
LE16 ddk_version;
|
||||
#endif
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_object_table_entry_t
|
||||
{
|
||||
__packed_struct(le_object_table_entry_t)
|
||||
LE32 virtual_size;
|
||||
LE32 base_address;
|
||||
LE32 flags;
|
||||
LE32 pagemap_index;
|
||||
LE32 npages;
|
||||
LE32 reserved;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct le_pagemap_entry_t
|
||||
{
|
||||
__packed_struct(le_pagemap_entry_t)
|
||||
unsigned char h;
|
||||
unsigned char m;
|
||||
unsigned char l;
|
||||
unsigned char type; // 0x00-legal;0x40-iterated;0x80-invalid;0xC0-zeroed
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
virtual void readObjectTable();
|
||||
virtual void writeObjectTable();
|
||||
|
||||
+430
-203
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,15 +21,15 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "linker.h"
|
||||
|
||||
static int hex(unsigned char c)
|
||||
static unsigned hex(unsigned char c)
|
||||
{
|
||||
return (c & 0xf) + (c > '9' ? 9 : 0);
|
||||
}
|
||||
@@ -45,17 +45,32 @@ static bool update_capacity(unsigned size, unsigned *capacity)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __acc_cdecl_va internal_error(const char *format, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
va_end(ap);
|
||||
|
||||
throwInternalError(buf);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// Section
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::Section::Section(const char *n, const void *i, unsigned s, unsigned a) :
|
||||
name(strdup(n)), output(NULL), size(s), offset(0), align(a), next(NULL)
|
||||
name(NULL), output(NULL), size(s), offset(0), p2align(a), next(NULL)
|
||||
{
|
||||
assert(name);
|
||||
name = strdup(n);
|
||||
assert(name != NULL);
|
||||
input = malloc(s + 1);
|
||||
assert(input);
|
||||
assert(input != NULL);
|
||||
memcpy(input, i, s);
|
||||
((char *)input)[s] = 0;
|
||||
}
|
||||
|
||||
ElfLinker::Section::~Section()
|
||||
@@ -64,10 +79,17 @@ ElfLinker::Section::~Section()
|
||||
free(input);
|
||||
}
|
||||
|
||||
ElfLinker::Symbol::Symbol(const char *n, Section *s, unsigned o) :
|
||||
name(strdup(n)), section(s), offset(o)
|
||||
|
||||
/*************************************************************************
|
||||
// Symbol
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::Symbol::Symbol(const char *n, Section *s, upx_uint64_t o) :
|
||||
name(NULL), section(s), offset(o)
|
||||
{
|
||||
assert(name);
|
||||
name = strdup(n);
|
||||
assert(name != NULL);
|
||||
assert(section != NULL);
|
||||
}
|
||||
|
||||
ElfLinker::Symbol::~Symbol()
|
||||
@@ -75,13 +97,113 @@ ElfLinker::Symbol::~Symbol()
|
||||
free(name);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Relocation
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::Relocation::Relocation(const Section *s, unsigned o, const char *t,
|
||||
const Symbol *v, unsigned a) :
|
||||
const Symbol *v, upx_uint64_t a) :
|
||||
section(s), offset(o), type(t), value(v), add(a)
|
||||
{}
|
||||
{
|
||||
assert(section != NULL);
|
||||
}
|
||||
|
||||
|
||||
void ElfLinker::preprocessSections(char *start, const char *end)
|
||||
/*************************************************************************
|
||||
// ElfLinker
|
||||
**************************************************************************/
|
||||
|
||||
ElfLinker::ElfLinker() :
|
||||
bele(&N_BELE_RTP::le_policy),
|
||||
input(NULL), output(NULL), head(NULL), tail(NULL),
|
||||
sections(NULL), symbols(NULL), relocations(NULL),
|
||||
nsections(0), nsections_capacity(0),
|
||||
nsymbols(0), nsymbols_capacity(0),
|
||||
nrelocations(0), nrelocations_capacity(0),
|
||||
reloc_done(false)
|
||||
{
|
||||
}
|
||||
|
||||
ElfLinker::~ElfLinker()
|
||||
{
|
||||
delete [] input;
|
||||
delete [] output;
|
||||
|
||||
unsigned ic;
|
||||
for (ic = 0; ic < nsections; ic++)
|
||||
delete sections[ic];
|
||||
free(sections);
|
||||
for (ic = 0; ic < nsymbols; ic++)
|
||||
delete symbols[ic];
|
||||
free(symbols);
|
||||
for (ic = 0; ic < nrelocations; ic++)
|
||||
delete relocations[ic];
|
||||
free(relocations);
|
||||
}
|
||||
|
||||
void ElfLinker::init(const void *pdata_v, int plen)
|
||||
{
|
||||
const upx_byte *pdata = (const upx_byte *) pdata_v;
|
||||
if (plen >= 16 && memcmp(pdata, "UPX#", 4) == 0)
|
||||
{
|
||||
// decompress pre-compressed stub-loader
|
||||
int method;
|
||||
unsigned u_len, c_len;
|
||||
if (pdata[4])
|
||||
{
|
||||
method = pdata[4];
|
||||
u_len = get_le16(pdata + 5);
|
||||
c_len = get_le16(pdata + 7);
|
||||
pdata += 9;
|
||||
assert(9 + c_len == (unsigned) plen);
|
||||
}
|
||||
else
|
||||
{
|
||||
method = pdata[5];
|
||||
u_len = get_le32(pdata + 6);
|
||||
c_len = get_le32(pdata + 10);
|
||||
pdata += 14;
|
||||
assert(14 + c_len == (unsigned) plen);
|
||||
}
|
||||
assert((unsigned) plen < u_len);
|
||||
inputlen = u_len;
|
||||
input = new upx_byte[inputlen + 1];
|
||||
unsigned new_len = u_len;
|
||||
int r = upx_decompress(pdata, c_len, input, &new_len, method, NULL);
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || new_len != u_len)
|
||||
throwBadLoader();
|
||||
}
|
||||
else
|
||||
{
|
||||
inputlen = plen;
|
||||
input = new upx_byte[inputlen + 1];
|
||||
memcpy(input, pdata, inputlen);
|
||||
}
|
||||
input[inputlen] = 0; // NUL terminate
|
||||
|
||||
output = new upx_byte[inputlen];
|
||||
outputlen = 0;
|
||||
|
||||
int pos = find(input, inputlen, "Sections:\n", 10);
|
||||
assert(pos != -1);
|
||||
char *psections = (char *) input + pos;
|
||||
|
||||
char *psymbols = strstr(psections, "SYMBOL TABLE:\n");
|
||||
assert(psymbols != NULL);
|
||||
|
||||
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR ");
|
||||
assert(prelocs != NULL);
|
||||
|
||||
preprocessSections(psections, psymbols);
|
||||
preprocessSymbols(psymbols, prelocs);
|
||||
preprocessRelocations(prelocs, (char*) input + inputlen);
|
||||
addLoader("*UND*");
|
||||
}
|
||||
|
||||
void ElfLinker::preprocessSections(char *start, char *end)
|
||||
{
|
||||
nsections = 0;
|
||||
while (start < end)
|
||||
@@ -107,36 +229,48 @@ void ElfLinker::preprocessSections(char *start, const char *end)
|
||||
addSection("*UND*", NULL, 0, 0);
|
||||
}
|
||||
|
||||
void ElfLinker::preprocessSymbols(char *start, const char *end)
|
||||
void ElfLinker::preprocessSymbols(char *start, char *end)
|
||||
{
|
||||
nsymbols = 0;
|
||||
while (start < end)
|
||||
{
|
||||
char section[1024];
|
||||
char symbol[1024];
|
||||
unsigned offset;
|
||||
unsigned value, offset;
|
||||
|
||||
char *nextl = strchr(start, '\n');
|
||||
assert(nextl != NULL);
|
||||
|
||||
if (sscanf(start, "%x%*8c %1024s %*x %1023s",
|
||||
&offset, section, symbol) == 3)
|
||||
if (sscanf(start, "%x g *ABS* %x %1023s",
|
||||
&value, &offset, symbol) == 3)
|
||||
{
|
||||
char *s = strstr(start, symbol);
|
||||
s[strlen(symbol)] = 0;
|
||||
addSymbol(s, "*ABS*", value);
|
||||
assert(offset == 0);
|
||||
}
|
||||
#if 0
|
||||
else if (sscanf(start, "%x%*8c %1023s %*x %1023s",
|
||||
#else
|
||||
// work around broken scanf() implementations
|
||||
// http://bugs.winehq.org/show_bug.cgi?id=10401 (fixed in Wine 0.9.58)
|
||||
else if (sscanf(start, "%x%*c%*c%*c%*c%*c%*c%*c%*c %1023s %*x %1023s",
|
||||
#endif
|
||||
&offset, section, symbol) == 3)
|
||||
{
|
||||
char *s = strstr(start, symbol);
|
||||
s[strlen(symbol)] = 0;
|
||||
|
||||
if (strcmp(section, "*UND*") == 0)
|
||||
offset = 0xdeaddead;
|
||||
assert(strcmp(section, "*ABS*") != 0);
|
||||
addSymbol(s, section, offset);
|
||||
|
||||
//printf("symbol %s preprocessed o=%x\n", s, offset);
|
||||
}
|
||||
|
||||
start = nextl + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ElfLinker::preprocessRelocations(char *start, const char *end)
|
||||
void ElfLinker::preprocessRelocations(char *start, char *end)
|
||||
{
|
||||
char sect[1024];
|
||||
Section *section = NULL;
|
||||
@@ -160,63 +294,76 @@ void ElfLinker::preprocessRelocations(char *start, const char *end)
|
||||
char *t = strstr(start, type);
|
||||
t[strlen(type)] = 0;
|
||||
|
||||
unsigned add = 0;
|
||||
if (char *p = strstr(symbol, "+0x"))
|
||||
upx_uint64_t add = 0;
|
||||
char *p = strstr(symbol, "+0x");
|
||||
if (p == NULL)
|
||||
p = strstr(symbol, "-0x");
|
||||
if (p)
|
||||
{
|
||||
// Beware: sscanf("0xfffffffffffffffc", "%x", &add) ==> -1 == add
|
||||
// because conversion stops after 32 bits for a non-long.
|
||||
// Also, glibc-2.3.5 has a bug: even using "%lx" still gives -1 instead of -4.
|
||||
long addend;
|
||||
char sign = *p;
|
||||
*p = 0; // terminate the symbol name
|
||||
p+=3;
|
||||
if ('f'==p[0] && 0==strncmp(p, "ffffffff", 8)) {
|
||||
p+=8; // workaround a bug in glibc-2.3.5
|
||||
}
|
||||
sscanf(p, "%lx", &addend);
|
||||
add = (unsigned)addend;
|
||||
p += 3;
|
||||
|
||||
assert(strlen(p) == 8 || strlen(p) == 16);
|
||||
char *endptr = NULL;
|
||||
upx_uint64_t ull = strtoull(p, &endptr, 16);
|
||||
add = (upx_uint64_t) ull;
|
||||
assert(add == ull);
|
||||
assert(endptr && *endptr == '\0');
|
||||
if (sign == '-')
|
||||
add = -add;
|
||||
}
|
||||
|
||||
addRelocation(section->name, offset, t, symbol, add);
|
||||
|
||||
//printf("relocation %s %x preprocessed\n", section->name, offset);
|
||||
//printf("relocation %s %s %x %llu preprocessed\n", section->name, symbol, offset, (unsigned long long) add);
|
||||
}
|
||||
|
||||
start = nextl + 1;
|
||||
}
|
||||
}
|
||||
|
||||
ElfLinker::Section *ElfLinker::findSection(const char *name) const
|
||||
ElfLinker::Section *ElfLinker::findSection(const char *name, bool fatal) const
|
||||
{
|
||||
for (unsigned ic = 0; ic < nsections; ic++)
|
||||
if (strcmp(sections[ic]->name, name) == 0)
|
||||
return sections[ic];
|
||||
|
||||
printf("unknown section %s\n", name);
|
||||
abort();
|
||||
if (fatal)
|
||||
internal_error("unknown section %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ElfLinker::Symbol *ElfLinker::findSymbol(const char *name) /*const*/
|
||||
ElfLinker::Symbol *ElfLinker::findSymbol(const char *name, bool fatal) const
|
||||
{
|
||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||
if (strcmp(symbols[ic]->name, name) == 0)
|
||||
return symbols[ic];
|
||||
|
||||
// FIXME: this should be a const method !
|
||||
if ('*' == name[0]) // *ABS*
|
||||
return addSymbol(name, name, 0);
|
||||
|
||||
printf("unknown symbol %s\n", name);
|
||||
abort();
|
||||
if (fatal)
|
||||
internal_error("unknown symbol %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
|
||||
unsigned offset)
|
||||
ElfLinker::Section *ElfLinker::addSection(const char *sname, const void *sdata, int slen, unsigned p2align)
|
||||
{
|
||||
//printf("addSection: %s len=%d align=%d\n", sname, slen, p2align);
|
||||
if (update_capacity(nsections, &nsections_capacity))
|
||||
sections = static_cast<Section **>(realloc(sections, nsections_capacity * sizeof(Section *)));
|
||||
assert(sections);
|
||||
assert(sname); assert(sname[0]); assert(sname[strlen(sname)-1] != ':');
|
||||
assert(findSection(sname, false) == NULL);
|
||||
Section *sec = new Section(sname, sdata, slen, p2align);
|
||||
sections[nsections++] = sec;
|
||||
return sec;
|
||||
}
|
||||
|
||||
ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
|
||||
upx_uint64_t offset)
|
||||
{
|
||||
//printf("addSymbol: %s %s 0x%x\n", name, section, offset);
|
||||
if (update_capacity(nsymbols, &nsymbols_capacity))
|
||||
symbols = static_cast<Symbol **>(realloc(symbols, nsymbols_capacity * sizeof(Symbol *)));
|
||||
assert(symbols != NULL);
|
||||
assert(name); assert(name[0]); assert(name[strlen(name)-1] != ':');
|
||||
assert(findSymbol(name, false) == NULL);
|
||||
Symbol *sym = new Symbol(name, findSection(section), offset);
|
||||
symbols[nsymbols++] = sym;
|
||||
return sym;
|
||||
@@ -224,7 +371,7 @@ ElfLinker::Symbol *ElfLinker::addSymbol(const char *name, const char *section,
|
||||
|
||||
ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned off,
|
||||
const char *type, const char *symbol,
|
||||
unsigned add)
|
||||
upx_uint64_t add)
|
||||
{
|
||||
if (update_capacity(nrelocations, &nrelocations_capacity))
|
||||
relocations = static_cast<Relocation **>(realloc(relocations, (nrelocations_capacity) * sizeof(Relocation *)));
|
||||
@@ -235,69 +382,18 @@ ElfLinker::Relocation *ElfLinker::addRelocation(const char *section, unsigned of
|
||||
return rel;
|
||||
}
|
||||
|
||||
ElfLinker::ElfLinker() :
|
||||
frozen(false), input(NULL), output(NULL), head(NULL), tail(NULL),
|
||||
sections(NULL), symbols(NULL), relocations(NULL),
|
||||
nsections(0), nsections_capacity(0),
|
||||
nsymbols(0), nsymbols_capacity(0),
|
||||
nrelocations(0), nrelocations_capacity(0)
|
||||
{
|
||||
}
|
||||
|
||||
ElfLinker::~ElfLinker()
|
||||
{
|
||||
delete [] input;
|
||||
delete [] output;
|
||||
|
||||
unsigned ic;
|
||||
for (ic = 0; ic < nsections; ic++)
|
||||
delete sections[ic];
|
||||
free(sections);
|
||||
for (ic = 0; ic < nsymbols; ic++)
|
||||
delete symbols[ic];
|
||||
free(symbols);
|
||||
for (ic = 0; ic < nrelocations; ic++)
|
||||
delete relocations[ic];
|
||||
free(relocations);
|
||||
}
|
||||
|
||||
void ElfLinker::init(const void *pdata, int plen)
|
||||
{
|
||||
upx_byte *i = new upx_byte[plen + 1];
|
||||
memcpy(i, pdata, plen);
|
||||
input = i;
|
||||
inputlen = plen;
|
||||
|
||||
output = new upx_byte[plen];
|
||||
outputlen = 0;
|
||||
|
||||
int pos = find(input, plen, "Sections:", 9);
|
||||
assert(pos != -1);
|
||||
char *psections = pos + (char *) input;
|
||||
|
||||
char *psymbols = strstr(psections, "SYMBOL TABLE:");
|
||||
assert(psymbols != NULL);
|
||||
|
||||
char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR");
|
||||
assert(prelocs != NULL);
|
||||
input[plen] = 0;
|
||||
|
||||
preprocessSections(psections, psymbols);
|
||||
preprocessSymbols(psymbols, prelocs);
|
||||
preprocessRelocations(prelocs, (char*) input + inputlen);
|
||||
addLoader("*UND*");
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ElfLinker::setLoaderAlignOffset(int phase)
|
||||
{
|
||||
//assert(phase & 0);
|
||||
printf("\nFIXME: ElfLinker::setLoaderAlignOffset %d\n", phase);
|
||||
}
|
||||
#endif
|
||||
|
||||
int ElfLinker::addLoader(const char *sname)
|
||||
{
|
||||
assert(!frozen);
|
||||
if (sname[0] == 0)
|
||||
assert(sname != NULL);
|
||||
if (!sname[0])
|
||||
return outputlen;
|
||||
|
||||
char *begin = strdup(sname);
|
||||
@@ -311,33 +407,35 @@ int ElfLinker::addLoader(const char *sname)
|
||||
break;
|
||||
}
|
||||
|
||||
if (*sect == '+') // alignment
|
||||
if (sect[0] == '+') // alignment
|
||||
{
|
||||
assert(tail);
|
||||
if (unsigned l = (hex(sect[2]) - tail->offset - tail->size)
|
||||
% hex(sect[1]))
|
||||
unsigned l = (hex(sect[2]) - tail->offset - tail->size) % hex(sect[1]);
|
||||
if (l)
|
||||
{
|
||||
alignCode(l);
|
||||
if (sect[3] == 'D')
|
||||
alignData(l);
|
||||
else
|
||||
alignCode(l);
|
||||
tail->size += l;
|
||||
outputlen += l;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Section *section = findSection(sect);
|
||||
if (section->align) {
|
||||
unsigned const v = ~0u << section->align;
|
||||
if (section->p2align) {
|
||||
assert(tail);
|
||||
if (unsigned const l = ~v & -(tail->offset + tail->size)) {
|
||||
assert(tail != section);
|
||||
unsigned const v = ~0u << section->p2align;
|
||||
if (unsigned const l = ~v & (0u-(tail->offset + tail->size))) {
|
||||
alignCode(l);
|
||||
tail->size += l;
|
||||
outputlen += l;
|
||||
}
|
||||
}
|
||||
memcpy(output + outputlen, section->input, section->size);
|
||||
section->output = output + outputlen;
|
||||
//printf("section added: 0x%04x %3d %s\n", outputlen, section->size, section->name);
|
||||
outputlen += section->size;
|
||||
//printf("section added: %s\n", sect);
|
||||
|
||||
if (head)
|
||||
{
|
||||
@@ -354,38 +452,39 @@ int ElfLinker::addLoader(const char *sname)
|
||||
return outputlen;
|
||||
}
|
||||
|
||||
void ElfLinker::addSection(const char *sname, const void *sdata, int slen, int align)
|
||||
void ElfLinker::addLoader(const char *s, va_list ap)
|
||||
{
|
||||
assert(!frozen);
|
||||
if (update_capacity(nsections, &nsections_capacity))
|
||||
sections = static_cast<Section **>(realloc(sections, nsections_capacity * sizeof(Section *)));
|
||||
assert(sections);
|
||||
Section *sec = new Section(sname, sdata, slen, align);
|
||||
sections[nsections++] = sec;
|
||||
//return sec;
|
||||
while (s != NULL)
|
||||
{
|
||||
addLoader(s);
|
||||
s = va_arg(ap, const char *);
|
||||
}
|
||||
}
|
||||
|
||||
void ElfLinker::freeze()
|
||||
void __acc_cdecl_va ElfLinker::addLoaderVA(const char *s, ...)
|
||||
{
|
||||
if (frozen)
|
||||
return;
|
||||
|
||||
frozen = true;
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
addLoader(s, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int ElfLinker::getSection(const char *sname, int *slen)
|
||||
int ElfLinker::getSection(const char *sname, int *slen) const
|
||||
{
|
||||
assert(frozen);
|
||||
Section *section = findSection(sname);
|
||||
const Section *section = findSection(sname);
|
||||
if (slen)
|
||||
*slen = section->size;
|
||||
return section->output - output;
|
||||
return (int) (section->output - output);
|
||||
}
|
||||
|
||||
upx_byte *ElfLinker::getLoader(int *llen)
|
||||
int ElfLinker::getSectionSize(const char *sname) const
|
||||
{
|
||||
assert(frozen);
|
||||
const Section *section = findSection(sname);
|
||||
return section->size;
|
||||
}
|
||||
|
||||
upx_byte *ElfLinker::getLoader(int *llen) const
|
||||
{
|
||||
if (llen)
|
||||
*llen = outputlen;
|
||||
return output;
|
||||
@@ -393,39 +492,44 @@ upx_byte *ElfLinker::getLoader(int *llen)
|
||||
|
||||
void ElfLinker::relocate()
|
||||
{
|
||||
assert(frozen);
|
||||
|
||||
assert(!reloc_done);
|
||||
reloc_done = true;
|
||||
for (unsigned ic = 0; ic < nrelocations; ic++)
|
||||
{
|
||||
Relocation *rel = relocations[ic];
|
||||
const Relocation *rel = relocations[ic];
|
||||
upx_uint64_t value = 0;
|
||||
|
||||
if (rel->section->output == NULL)
|
||||
continue;
|
||||
if (rel->value->section->output == NULL)
|
||||
if (strcmp(rel->value->section->name, "*ABS*") == 0)
|
||||
{
|
||||
printf("can not apply reloc '%s:%x' without section '%s'\n",
|
||||
rel->section->name, rel->offset,
|
||||
rel->value->section->name);
|
||||
abort();
|
||||
value = rel->value->offset;
|
||||
}
|
||||
|
||||
if (strcmp(rel->value->section->name, "*UND*") == 0 &&
|
||||
rel->value->offset == 0xdeaddead)
|
||||
else if (strcmp(rel->value->section->name, "*UND*") == 0 &&
|
||||
rel->value->offset == 0xdeaddead)
|
||||
internal_error("undefined symbol '%s' referenced\n", rel->value->name);
|
||||
else if (rel->value->section->output == NULL)
|
||||
internal_error("can not apply reloc '%s:%x' without section '%s'\n",
|
||||
rel->section->name, rel->offset,
|
||||
rel->value->section->name);
|
||||
else
|
||||
{
|
||||
printf("undefined symbol '%s' referenced\n", rel->value->name);
|
||||
abort();
|
||||
value = rel->value->section->offset +
|
||||
rel->value->offset + rel->add;
|
||||
}
|
||||
unsigned value = rel->value->section->offset +
|
||||
rel->value->offset + rel->add;
|
||||
upx_byte *location = rel->section->output + rel->offset;
|
||||
|
||||
//printf("%-28s %-28s %-10s 0x%16llx 0x%16llx\n", rel->section->name, rel->value->name, rel->type, (long long) value, (long long) value - rel->section->offset - rel->offset);
|
||||
//printf(" %llx %d %llx %d %llx : %d\n", (long long) value, rel->value->section->offset, rel->value->offset, rel->offset, (long long) rel->add, *location);
|
||||
relocate1(rel, location, value, rel->type);
|
||||
}
|
||||
}
|
||||
|
||||
void ElfLinker::defineSymbol(const char *name, unsigned value)
|
||||
void ElfLinker::defineSymbol(const char *name, upx_uint64_t value)
|
||||
{
|
||||
Symbol *symbol = findSymbol(name);
|
||||
if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
|
||||
if (strcmp(symbol->section->name, "*ABS*") == 0)
|
||||
internal_error("defineSymbol: symbol '%s' is *ABS*\n", name);
|
||||
else if (strcmp(symbol->section->name, "*UND*") == 0) // for undefined symbols
|
||||
symbol->offset = value;
|
||||
else if (strcmp(symbol->section->name, name) == 0) // for sections
|
||||
{
|
||||
@@ -437,87 +541,128 @@ void ElfLinker::defineSymbol(const char *name, unsigned value)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("symbol '%s' already defined\n", name);
|
||||
abort();
|
||||
}
|
||||
internal_error("defineSymbol: symbol '%s' already defined\n", name);
|
||||
}
|
||||
|
||||
// debugging support
|
||||
void ElfLinker::dumpSymbols(FILE *fp) const
|
||||
void ElfLinker::dumpSymbol(const Symbol *symbol, unsigned flags, FILE *fp) const
|
||||
{
|
||||
if ((flags & 1) && symbol->section->output == NULL)
|
||||
return;
|
||||
char d0[16+1], d1[16+1];
|
||||
upx_snprintf(d0, sizeof(d0), "%016llx", (upx_uint64_t) symbol->offset);
|
||||
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) symbol->section->offset);
|
||||
fprintf(fp, "%-28s 0x%-16s | %-28s 0x%-16s\n",
|
||||
symbol->name, d0, symbol->section->name, d1);
|
||||
}
|
||||
void ElfLinker::dumpSymbols(unsigned flags, FILE *fp) const
|
||||
{
|
||||
if (fp == NULL)
|
||||
fp = stdout;
|
||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||
if ((flags & 2) == 0)
|
||||
{
|
||||
Symbol *symbol = symbols[ic];
|
||||
fprintf(fp, "%-20s 0x%08x | %-20s 0x%08x\n",
|
||||
symbol->name, symbol->offset, symbol->section->name, symbol->section->offset);
|
||||
// default: dump symbols in used section order
|
||||
for (const Section *section = head; section; section = section->next)
|
||||
{
|
||||
char d1[16+1];
|
||||
upx_snprintf(d1, sizeof(d1), "%016llx", (upx_uint64_t) section->offset);
|
||||
fprintf(fp, "%-42s%-28s 0x%-16s\n", "", section->name, d1);
|
||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||
{
|
||||
const Symbol *symbol = symbols[ic];
|
||||
if (symbol->section == section && strcmp(symbol->name, section->name) != 0)
|
||||
dumpSymbol(symbol, flags, fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// dump all symbols
|
||||
for (unsigned ic = 0; ic < nsymbols; ic++)
|
||||
dumpSymbol(symbols[ic], flags, fp);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ElfLinker::getSymbolOffset(const char *name) const
|
||||
upx_uint64_t ElfLinker::getSymbolOffset(const char *name) const
|
||||
{
|
||||
assert(frozen);
|
||||
Symbol *symbol = const_cast<ElfLinker *>(this)->findSymbol(name);
|
||||
const Symbol *symbol = findSymbol(name);
|
||||
if (symbol->section->output == NULL)
|
||||
return 0xdeaddead;
|
||||
return symbol->section->offset + symbol->offset;
|
||||
}
|
||||
|
||||
void ElfLinker::alignWithByte(unsigned len, upx_byte b)
|
||||
void ElfLinker::alignWithByte(unsigned len, unsigned char b)
|
||||
{
|
||||
memset(output + outputlen, b, len);
|
||||
outputlen += len;
|
||||
}
|
||||
|
||||
void ElfLinker::relocate1(const Relocation *rel, upx_byte *,
|
||||
unsigned, const char *)
|
||||
upx_uint64_t, const char *)
|
||||
{
|
||||
printf("unknown relocation type '%s\n", rel->type);
|
||||
abort();
|
||||
internal_error("unknown relocation type '%s\n", rel->type);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ElfLinker arch subclasses
|
||||
// FIXME: add more displacment overflow checks
|
||||
// FIXME: add support for our special "ignore_reloc_overflow" section
|
||||
**************************************************************************/
|
||||
|
||||
#if 0 // FIXME
|
||||
static void check8(const Relocation *rel, const upx_byte *location, int v, int d)
|
||||
{
|
||||
if (v < -128 || v > 127)
|
||||
internal_error("value out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
if (d < -128 || d > 127)
|
||||
internal_error("displacement target out of range (%d) in reloc %s:%x\n",
|
||||
v, rel->section->name, rel->offset);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ElfLinkerAMD64::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_X86_64_", 9))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
type += 9;
|
||||
|
||||
bool range_check = false;
|
||||
if (strncmp(type, "PC", 2) == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
type += 2;
|
||||
range_check = true;
|
||||
}
|
||||
|
||||
if (strcmp(type, "8") == 0)
|
||||
{
|
||||
#if (ACC_CC_PGI)
|
||||
int displ = * (signed char *) location + (int) value; // CBUG
|
||||
#else
|
||||
int displ = (signed char) *location + (int) value;
|
||||
if (displ < -128 || displ > 127)
|
||||
{
|
||||
printf("target out of range (%d) in reloc %s:%x\n",
|
||||
displ, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
if (range_check && (displ < -128 || displ > 127))
|
||||
internal_error("target out of range (%d) in reloc %s:%x\n",
|
||||
displ, rel->section->name, rel->offset);
|
||||
*location += value;
|
||||
}
|
||||
else if (strcmp(type, "16") == 0)
|
||||
set_le16(location, get_le16(location) + value);
|
||||
else if (strcmp(type, "32") == 0)
|
||||
else if (strncmp(type, "32", 2) == 0) // for "32" and "32S"
|
||||
set_le32(location, get_le32(location) + value);
|
||||
else if (strcmp(type, "64") == 0)
|
||||
set_le64(location, get_le64(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strcmp(type, "R_ARM_PC24") == 0)
|
||||
{
|
||||
@@ -528,7 +673,10 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_be32(location, get_be32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_be16(location) & 0x7ff) << 12);
|
||||
@@ -540,13 +688,16 @@ void ElfLinkerArmBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
//(b, 0xF000 + ((v - 1) / 2) * 0x10000);
|
||||
//set_be32(location, get_be32(location) + value / 4);
|
||||
}
|
||||
else if (0==strcmp("R_ARM_ABS8", type)) {
|
||||
*location += value;
|
||||
}
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strcmp(type, "R_ARM_PC24") == 0)
|
||||
{
|
||||
@@ -557,7 +708,10 @@ void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
{
|
||||
set_le32(location, get_le32(location) + value);
|
||||
}
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0)
|
||||
else if (strcmp(type, "R_ARM_THM_CALL") == 0
|
||||
|| strcmp(type, "R_ARM_THM_XPC22") == 0
|
||||
|| strcmp(type, "R_ARM_THM_PC22") == 0
|
||||
)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
value += ((get_le16(location) & 0x7ff) << 12);
|
||||
@@ -569,6 +723,9 @@ void ElfLinkerArmLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
//(b, 0xF000 + ((v - 1) / 2) * 0x10000);
|
||||
//set_le32(location, get_le32(location) + value / 4);
|
||||
}
|
||||
else if (0==strcmp("R_ARM_ABS8", type)) {
|
||||
*location += value;
|
||||
}
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
@@ -580,10 +737,11 @@ void ElfLinkerM68k::alignCode(unsigned len)
|
||||
assert((outputlen & 1) == 0);
|
||||
for (unsigned i = 0; i < len; i += 2)
|
||||
set_be16(output + outputlen + i, 0x4e71); // "nop"
|
||||
outputlen += len;
|
||||
}
|
||||
|
||||
void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_68K_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
@@ -594,24 +752,95 @@ void ElfLinkerM68k::relocate1(const Relocation *rel, upx_byte *location,
|
||||
value -= rel->section->offset + rel->offset;
|
||||
type += 2;
|
||||
}
|
||||
if (strcmp(type, "8") == 0)
|
||||
if (strcmp(type, "8") == 0) {
|
||||
*location += value;
|
||||
else if (strcmp(type, "16") == 0)
|
||||
}
|
||||
else if (strcmp(type, "16") == 0) {
|
||||
set_be16(location, get_be16(location) + value);
|
||||
else if (strcmp(type, "32") == 0)
|
||||
}
|
||||
else if (strcmp(type, "32") == 0) {
|
||||
set_be32(location, get_be32(location) + value);
|
||||
}
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerMipsBE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
#define MIPS_LO(a) ((a) & 0xffff)
|
||||
#define MIPS_PC16(a) ((a) >> 2)
|
||||
#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2)
|
||||
|
||||
if (strcmp(type, "R_MIPS_HI16") == 0)
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_HI(value));
|
||||
else if (strcmp(type, "R_MIPS_LO16") == 0)
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_LO(value));
|
||||
else if (strcmp(type, "R_MIPS_PC16") == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
set_be16(2+location, get_be16(2+location) + MIPS_PC16(value));
|
||||
}
|
||||
else if (strcmp(type, "R_MIPS_26") == 0)
|
||||
set_be32(location, get_be32(location) + MIPS_PC26(value));
|
||||
else if (strcmp(type, "R_MIPS_32") == 0)
|
||||
set_be32(location, get_be32(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
|
||||
#undef MIPS_HI
|
||||
#undef MIPS_LO
|
||||
#undef MIPS_PC16
|
||||
#undef MIPS_PC26
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerMipsLE::relocate1(const Relocation *rel, upx_byte *location,
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
#define MIPS_LO(a) ((a) & 0xffff)
|
||||
#define MIPS_PC16(a) ((a) >> 2)
|
||||
#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2)
|
||||
|
||||
if (strcmp(type, "R_MIPS_HI16") == 0)
|
||||
set_le16(location, get_le16(location) + MIPS_HI(value));
|
||||
else if (strcmp(type, "R_MIPS_LO16") == 0)
|
||||
set_le16(location, get_le16(location) + MIPS_LO(value));
|
||||
else if (strcmp(type, "R_MIPS_PC16") == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
set_le16(location, get_le16(location) + MIPS_PC16(value));
|
||||
}
|
||||
else if (strcmp(type, "R_MIPS_26") == 0)
|
||||
set_le32(location, get_le32(location) + MIPS_PC26(value));
|
||||
else if (strcmp(type, "R_MIPS_32") == 0)
|
||||
set_le32(location, get_le32(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
|
||||
#undef MIPS_HI
|
||||
#undef MIPS_LO
|
||||
#undef MIPS_PC16
|
||||
#undef MIPS_PC26
|
||||
}
|
||||
|
||||
|
||||
void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_PPC_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
type += 6;
|
||||
|
||||
if (strcmp(type, "ADDR32") == 0)
|
||||
{
|
||||
set_be32(location, get_be32(location) + value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(type, "REL", 3) == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
@@ -622,19 +851,15 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
// Note that original (*location).displ is ignored.
|
||||
if (strcmp(type, "24") == 0) {
|
||||
if (3& value) {
|
||||
printf("unaligned word diplacement");
|
||||
abort();
|
||||
}
|
||||
if (3& value)
|
||||
internal_error("unaligned word diplacement");
|
||||
// FIXME: displacment overflow?
|
||||
set_be32(location, (0xfc000003 & get_be32(location)) +
|
||||
(0x03fffffc & value));
|
||||
}
|
||||
else if (strcmp(type, "14") == 0) {
|
||||
if (3& value) {
|
||||
printf("unaligned word diplacement");
|
||||
abort();
|
||||
}
|
||||
if (3& value)
|
||||
internal_error("unaligned word diplacement");
|
||||
// FIXME: displacment overflow?
|
||||
set_be32(location, (0xffff0003 & get_be32(location)) +
|
||||
(0x0000fffc & value));
|
||||
@@ -645,28 +870,30 @@ void ElfLinkerPpc32::relocate1(const Relocation *rel, upx_byte *location,
|
||||
|
||||
|
||||
void ElfLinkerX86::relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
upx_uint64_t value, const char *type)
|
||||
{
|
||||
if (strncmp(type, "R_386_", 6))
|
||||
return super::relocate1(rel, location, value, type);
|
||||
type += 6;
|
||||
|
||||
int range_check = 0;
|
||||
bool range_check = false;
|
||||
if (strncmp(type, "PC", 2) == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
type += 2;
|
||||
range_check = 1;
|
||||
range_check = true;
|
||||
}
|
||||
|
||||
if (strcmp(type, "8") == 0)
|
||||
{
|
||||
#if (ACC_CC_PGI)
|
||||
int displ = * (signed char *) location + (int) value; // CBUG
|
||||
#else
|
||||
int displ = (signed char) *location + (int) value;
|
||||
if (range_check && (displ < -128 || displ > 127)) {
|
||||
printf("target out of range (%d) in reloc %s:%x\n",
|
||||
displ, rel->section->name, rel->offset);
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
if (range_check && (displ < -128 || displ > 127))
|
||||
internal_error("target out of range (%d,%d,%d) in reloc %s:%x\n",
|
||||
displ, *location, value, rel->section->name, rel->offset);
|
||||
*location += value;
|
||||
}
|
||||
else if (strcmp(type, "16") == 0)
|
||||
|
||||
+88
-41
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,28 +21,29 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_LINKER_H
|
||||
#define __UPX_LINKER_H
|
||||
#define __UPX_LINKER_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ElfLinker
|
||||
**************************************************************************/
|
||||
|
||||
class ElfLinker : private nocopy
|
||||
class ElfLinker : private noncopyable
|
||||
{
|
||||
friend class Packer;
|
||||
public:
|
||||
const N_BELE_RTP::AbstractPolicy *bele; // target endianness
|
||||
protected:
|
||||
struct Section;
|
||||
struct Symbol;
|
||||
struct Relocation;
|
||||
|
||||
bool frozen; // FIXME: can we remove this ?
|
||||
|
||||
upx_byte *input;
|
||||
int inputlen;
|
||||
upx_byte *output;
|
||||
@@ -62,49 +63,69 @@ protected:
|
||||
unsigned nrelocations;
|
||||
unsigned nrelocations_capacity;
|
||||
|
||||
void preprocessSections(char *start, const char *end);
|
||||
void preprocessSymbols(char *start, const char *end);
|
||||
void preprocessRelocations(char *start, const char *end);
|
||||
Section *findSection(const char *name) const;
|
||||
Symbol *findSymbol(const char *name) /*const*/;
|
||||
bool reloc_done;
|
||||
|
||||
Symbol *addSymbol(const char *name, const char *section, unsigned offset);
|
||||
protected:
|
||||
void preprocessSections(char *start, char *end);
|
||||
void preprocessSymbols(char *start, char *end);
|
||||
void preprocessRelocations(char *start, char *end);
|
||||
Section *findSection(const char *name, bool fatal=true) const;
|
||||
Symbol *findSymbol(const char *name, bool fatal=true) const;
|
||||
|
||||
Symbol *addSymbol(const char *name, const char *section, upx_uint64_t offset);
|
||||
Relocation *addRelocation(const char *section, unsigned off, const char *type,
|
||||
const char *symbol, unsigned add);
|
||||
const char *symbol, upx_uint64_t add);
|
||||
|
||||
public:
|
||||
ElfLinker();
|
||||
virtual ~ElfLinker();
|
||||
|
||||
virtual void init(const void *pdata, int plen);
|
||||
virtual void setLoaderAlignOffset(int phase);
|
||||
//virtual void setLoaderAlignOffset(int phase);
|
||||
virtual int addLoader(const char *sname);
|
||||
virtual void addSection(const char *sname, const void *sdata, int slen, int align);
|
||||
virtual void freeze();
|
||||
virtual int getSection(const char *sname, int *slen=NULL);
|
||||
virtual upx_byte *getLoader(int *llen=NULL);
|
||||
virtual void relocate();
|
||||
virtual void defineSymbol(const char *name, unsigned value);
|
||||
virtual unsigned getSymbolOffset(const char *) const;
|
||||
virtual void dumpSymbols(FILE *fp=NULL) const;
|
||||
void addLoader(const char *s, va_list ap);
|
||||
#if 1 && (ACC_CC_CLANG || (ACC_CC_GNUC >= 0x040100))
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...) __attribute__((__sentinel__));
|
||||
#else
|
||||
void __acc_cdecl_va addLoaderVA(const char *s, ...);
|
||||
#endif
|
||||
virtual Section *addSection(const char *sname, const void *sdata, int slen, unsigned p2align);
|
||||
virtual int getSection(const char *sname, int *slen=NULL) const;
|
||||
virtual int getSectionSize(const char *sname) const;
|
||||
virtual upx_byte *getLoader(int *llen=NULL) const;
|
||||
virtual void defineSymbol(const char *name, upx_uint64_t value);
|
||||
virtual upx_uint64_t getSymbolOffset(const char *) const;
|
||||
|
||||
void alignWithByte(unsigned len, upx_byte b);
|
||||
virtual void dumpSymbol(const Symbol *, unsigned flags, FILE *fp) const;
|
||||
virtual void dumpSymbols(unsigned flags=0, FILE *fp=NULL) const;
|
||||
|
||||
void alignWithByte(unsigned len, unsigned char b);
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0); }
|
||||
virtual void alignData(unsigned len) { alignWithByte(len, 0); }
|
||||
|
||||
protected:
|
||||
virtual void relocate();
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
|
||||
// target endianness abstraction
|
||||
unsigned get_te16(const void *p) const { return bele->get16(p); }
|
||||
unsigned get_te32(const void *p) const { return bele->get32(p); }
|
||||
upx_uint64_t get_te64(const void *p) const { return bele->get64(p); }
|
||||
void set_te16(void *p, unsigned v) const { bele->set16(p, v); }
|
||||
void set_te32(void *p, unsigned v) const { bele->set32(p, v); }
|
||||
void set_te64(void *p, upx_uint64_t v) const { bele->set64(p, v); }
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Section : private nocopy
|
||||
struct ElfLinker::Section : private noncopyable
|
||||
{
|
||||
char *name;
|
||||
void *input;
|
||||
upx_byte *output;
|
||||
unsigned size;
|
||||
unsigned offset;
|
||||
unsigned char align; // log2
|
||||
upx_uint64_t offset;
|
||||
unsigned p2align; // log2
|
||||
Section *next;
|
||||
|
||||
Section(const char *n, const void *i, unsigned s, unsigned a=0);
|
||||
@@ -112,27 +133,27 @@ struct ElfLinker::Section : private nocopy
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Symbol : private nocopy
|
||||
struct ElfLinker::Symbol : private noncopyable
|
||||
{
|
||||
char *name;
|
||||
Section *section;
|
||||
unsigned offset;
|
||||
upx_uint64_t offset;
|
||||
|
||||
Symbol(const char *n, Section *s, unsigned o);
|
||||
Symbol(const char *n, Section *s, upx_uint64_t o);
|
||||
~Symbol();
|
||||
};
|
||||
|
||||
|
||||
struct ElfLinker::Relocation : private nocopy
|
||||
struct ElfLinker::Relocation : private noncopyable
|
||||
{
|
||||
const Section *section;
|
||||
unsigned offset;
|
||||
const char *type;
|
||||
const Symbol *value;
|
||||
unsigned add; // used in .rela relocations
|
||||
upx_uint64_t add; // used in .rela relocations
|
||||
|
||||
Relocation(const Section *s, unsigned o, const char *t,
|
||||
const Symbol *v, unsigned a);
|
||||
const Symbol *v, upx_uint64_t a);
|
||||
};
|
||||
|
||||
|
||||
@@ -146,16 +167,18 @@ class ElfLinkerAMD64 : public ElfLinker
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerArmBE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
public:
|
||||
ElfLinkerArmBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -164,26 +187,50 @@ class ElfLinkerArmLE : public ElfLinker
|
||||
typedef ElfLinker super;
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerM68k : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
public:
|
||||
ElfLinkerM68k() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void alignCode(unsigned len);
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsBE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
public:
|
||||
ElfLinkerMipsBE() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerMipsLE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
class ElfLinkerPpc32 : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
public:
|
||||
ElfLinkerPpc32() { bele = &N_BELE_RTP::be_policy; }
|
||||
protected:
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
@@ -193,7 +240,7 @@ class ElfLinkerX86 : public ElfLinker
|
||||
protected:
|
||||
virtual void alignCode(unsigned len) { alignWithByte(len, 0x90); }
|
||||
virtual void relocate1(const Relocation *, upx_byte *location,
|
||||
unsigned value, const char *type);
|
||||
upx_uint64_t value, const char *type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+367
-146
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,11 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#include "conf.h"
|
||||
#include "mygetopt.h"
|
||||
#include "file.h"
|
||||
#include "packer.h"
|
||||
#include "p_elf.h"
|
||||
@@ -43,23 +42,27 @@ int _crt0_startup_flags = _CRT0_FLAG_UNIX_SBRK;
|
||||
// options
|
||||
**************************************************************************/
|
||||
|
||||
void init_options(struct options_t *o)
|
||||
void options_t::reset()
|
||||
{
|
||||
options_t *o = this;
|
||||
memset(o, 0, sizeof(*o));
|
||||
o->crp.reset();
|
||||
|
||||
o->cmd = CMD_NONE;
|
||||
o->method = -1;
|
||||
o->method = M_NONE;
|
||||
o->level = -1;
|
||||
o->filter = -1;
|
||||
o->filter = FT_NONE;
|
||||
|
||||
o->backup = -1;
|
||||
o->overlay = -1;
|
||||
o->preserve_mode = true;
|
||||
o->preserve_ownership = true;
|
||||
o->preserve_timestamp = true;
|
||||
|
||||
o->console = CON_FILE;
|
||||
#if defined(__DJGPP__)
|
||||
o->console = CON_INIT;
|
||||
#elif defined(USE_SCREEN_WIN32)
|
||||
#elif (USE_SCREEN_WIN32)
|
||||
o->console = CON_INIT;
|
||||
#elif 1 && defined(__linux__)
|
||||
o->console = CON_INIT;
|
||||
@@ -76,8 +79,8 @@ void init_options(struct options_t *o)
|
||||
o->win32_pe.keep_resource = "";
|
||||
}
|
||||
|
||||
static struct options_t global_options;
|
||||
struct options_t *opt = &global_options;
|
||||
static options_t global_options;
|
||||
options_t *opt = &global_options;
|
||||
|
||||
static int done_output_name = 0;
|
||||
static int done_script_name = 0;
|
||||
@@ -86,6 +89,19 @@ static int done_script_name = 0;
|
||||
const char *argv0 = "";
|
||||
const char *progname = "";
|
||||
|
||||
static acc_getopt_t mfx_getopt;
|
||||
#define mfx_optarg mfx_getopt.optarg
|
||||
#define mfx_optind mfx_getopt.optind
|
||||
#define mfx_option acc_getopt_longopt_t
|
||||
static void handle_opterr(acc_getopt_p g, const char *f, void *v)
|
||||
{
|
||||
struct A { va_list ap; };
|
||||
struct A *a = (struct A *) v;
|
||||
fprintf( stderr, "%s: ", g->progname);
|
||||
vfprintf(stderr, f, a->ap);
|
||||
fprintf( stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
static int num_files = -1;
|
||||
static int exit_code = EXIT_OK;
|
||||
@@ -182,7 +198,7 @@ static void e_method(int m, int l)
|
||||
static void e_optarg(const char *n)
|
||||
{
|
||||
fflush(con_term);
|
||||
fprintf(stderr,"%s: invalid argument in option `%s'\n", argv0, n);
|
||||
fprintf(stderr,"%s: invalid argument in option '%s'\n", argv0, n);
|
||||
e_exit(EXIT_USAGE);
|
||||
}
|
||||
|
||||
@@ -190,7 +206,7 @@ static void e_optarg(const char *n)
|
||||
static void e_optval(const char *n)
|
||||
{
|
||||
fflush(con_term);
|
||||
fprintf(stderr,"%s: invalid value for option `%s'\n", argv0, n);
|
||||
fprintf(stderr,"%s: invalid value for option '%s'\n", argv0, n);
|
||||
e_exit(EXIT_USAGE);
|
||||
}
|
||||
|
||||
@@ -200,10 +216,10 @@ void e_envopt(const char *n)
|
||||
{
|
||||
fflush(con_term);
|
||||
if (n)
|
||||
fprintf(stderr,"%s: invalid string `%s' in environment variable `%s'\n",
|
||||
fprintf(stderr,"%s: invalid string '%s' in environment variable '%s'\n",
|
||||
argv0, n, OPTIONS_VAR);
|
||||
else
|
||||
fprintf(stderr,"%s: illegal option in environment variable `%s'\n",
|
||||
fprintf(stderr,"%s: illegal option in environment variable '%s'\n",
|
||||
argv0, OPTIONS_VAR);
|
||||
e_exit(EXIT_USAGE);
|
||||
}
|
||||
@@ -226,7 +242,7 @@ void check_not_both(bool e1, bool e2, const char *c1, const char *c2)
|
||||
if (e1 && e2)
|
||||
{
|
||||
fprintf(stderr,"%s: ",argv0);
|
||||
fprintf(stderr,"cannot use both `%s' and `%s'\n", c1, c2);
|
||||
fprintf(stderr,"cannot use both '%s' and '%s'\n", c1, c2);
|
||||
e_usage();
|
||||
}
|
||||
}
|
||||
@@ -236,12 +252,24 @@ void check_options(int i, int argc)
|
||||
{
|
||||
assert(i <= argc);
|
||||
|
||||
if (opt->cmd != CMD_COMPRESS)
|
||||
{
|
||||
// invalidate compression options
|
||||
opt->method = 0;
|
||||
opt->level = 0;
|
||||
opt->exact = 0;
|
||||
opt->small = 0;
|
||||
opt->crp.reset();
|
||||
}
|
||||
|
||||
// set default overlay action
|
||||
if (!(opt->cmd == CMD_COMPRESS || opt->cmd == CMD_DECOMPRESS))
|
||||
opt->overlay = opt->COPY_OVERLAY;
|
||||
else if (opt->overlay < 0)
|
||||
opt->overlay = opt->COPY_OVERLAY;
|
||||
|
||||
check_not_both(opt->exact, opt->overlay == opt->STRIP_OVERLAY, "--exact", "--overlay=strip");
|
||||
|
||||
// set default backup option
|
||||
if (opt->backup < 0)
|
||||
opt->backup = 0;
|
||||
@@ -251,14 +279,14 @@ void check_options(int i, int argc)
|
||||
check_not_both(opt->to_stdout, opt->output_name != NULL, "--stdout", "-o");
|
||||
if (opt->to_stdout && opt->cmd == CMD_COMPRESS)
|
||||
{
|
||||
fprintf(stderr,"%s: cannot use `--stdout' when compressing\n", argv0);
|
||||
fprintf(stderr,"%s: cannot use '--stdout' when compressing\n", argv0);
|
||||
e_usage();
|
||||
}
|
||||
if (opt->to_stdout || opt->output_name)
|
||||
{
|
||||
if (i + 1 != argc)
|
||||
{
|
||||
fprintf(stderr,"%s: need exactly one argument when using `%s'\n",
|
||||
fprintf(stderr,"%s: need exactly one argument when using '%s'\n",
|
||||
argv0, opt->to_stdout ? "--stdout" : "-o");
|
||||
e_usage();
|
||||
}
|
||||
@@ -299,8 +327,14 @@ static bool set_method(int m, int l)
|
||||
{
|
||||
if (!Packer::isValidCompressionMethod(m))
|
||||
return false;
|
||||
opt->method = m;
|
||||
opt->all_methods = false;
|
||||
#if 1
|
||||
// something like "--brute --lzma" should not disable "--brute"
|
||||
if (!opt->all_methods)
|
||||
#endif
|
||||
{
|
||||
opt->method = m;
|
||||
opt->all_methods = false;
|
||||
}
|
||||
}
|
||||
if (l > 0)
|
||||
opt->level = l;
|
||||
@@ -314,7 +348,7 @@ static void set_output_name(const char *n, bool allow_m)
|
||||
#if 1
|
||||
if (done_output_name > 0)
|
||||
{
|
||||
fprintf(stderr,"%s: option `-o' more than once given\n",argv0);
|
||||
fprintf(stderr,"%s: option '-o' more than once given\n",argv0);
|
||||
e_usage();
|
||||
}
|
||||
#endif
|
||||
@@ -337,7 +371,7 @@ static void set_script_name(const char *n, bool allow_m)
|
||||
#if 1
|
||||
if (done_script_name > 0)
|
||||
{
|
||||
fprintf(stderr,"%s: option `--script' more than once given\n",argv0);
|
||||
fprintf(stderr,"%s: option '--script' more than once given\n",argv0);
|
||||
e_usage();
|
||||
}
|
||||
#endif
|
||||
@@ -405,28 +439,58 @@ char* prepare_shortopts(char *buf, const char *n,
|
||||
|
||||
|
||||
template <class T>
|
||||
int getoptvar(T *var, const T minval, const T maxval)
|
||||
int getoptvar(T *var, const T min_value, const T max_value, const char *arg_fatal)
|
||||
{
|
||||
const char *p = mfx_optarg;
|
||||
char *endptr;
|
||||
int r = 0;
|
||||
long n;
|
||||
T v;
|
||||
|
||||
if (!p || !p[0])
|
||||
return -1;
|
||||
{ r = -1; goto error; }
|
||||
// avoid interpretation as octal value
|
||||
while (p[0] == '0' && isdigit(p[1]))
|
||||
p++;
|
||||
long n = strtol(p, &endptr, 0);
|
||||
n = strtol(p, &endptr, 0);
|
||||
if (*endptr != '\0')
|
||||
return -2;
|
||||
T v = (T) n;
|
||||
if (v < minval)
|
||||
return -3;
|
||||
if (v > maxval)
|
||||
return -4;
|
||||
{ r = -2; goto error; }
|
||||
v = (T) n;
|
||||
if (v < min_value)
|
||||
{ r = -3; goto error; }
|
||||
if (v > max_value)
|
||||
{ r = -4; goto error; }
|
||||
*var = v;
|
||||
return 0;
|
||||
goto done;
|
||||
error:
|
||||
if (arg_fatal != NULL)
|
||||
e_optval(arg_fatal);
|
||||
done:
|
||||
return r;
|
||||
}
|
||||
|
||||
#if 1 && (ACC_CC_GNUC >= 0x030300)
|
||||
template <class T, T default_value, T min_value, T max_value>
|
||||
int getoptvar(OptVar<T,default_value,min_value,max_value> *var, const char *arg_fatal)
|
||||
{
|
||||
T v = default_value;
|
||||
int r = getoptvar(&v, min_value, max_value, arg_fatal);
|
||||
if (r == 0)
|
||||
*var = v;
|
||||
return r;
|
||||
}
|
||||
#else
|
||||
template <class T>
|
||||
int getoptvar(T *var, const char *arg_fatal)
|
||||
{
|
||||
typename T::Type v = T::default_value_c;
|
||||
int r = getoptvar(&v, T::min_value_c, T::max_value_c, arg_fatal);
|
||||
if (r == 0)
|
||||
*var = v;
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static int do_option(int optc, const char *arg)
|
||||
{
|
||||
@@ -450,7 +514,7 @@ static int do_option(int optc, const char *arg)
|
||||
case 'f':
|
||||
opt->force++;
|
||||
break;
|
||||
case 902:
|
||||
case 909:
|
||||
set_cmd(CMD_FILEINFO);
|
||||
break;
|
||||
case 'h':
|
||||
@@ -459,10 +523,13 @@ static int do_option(int optc, const char *arg)
|
||||
set_cmd(CMD_HELP);
|
||||
break;
|
||||
case 'h'+256:
|
||||
#if 0
|
||||
/* according to GNU standards */
|
||||
set_term(stdout);
|
||||
opt->console = CON_FILE;
|
||||
#if 1
|
||||
if (!acc_isatty(STDOUT_FILENO))
|
||||
{
|
||||
/* according to GNU standards */
|
||||
set_term(stdout);
|
||||
opt->console = CON_FILE;
|
||||
}
|
||||
#endif
|
||||
show_help(1);
|
||||
e_exit(EXIT_OK);
|
||||
@@ -501,22 +568,32 @@ static int do_option(int optc, const char *arg)
|
||||
|
||||
// method
|
||||
case 702:
|
||||
opt->method_nrv2b_seen = true;
|
||||
if (!set_method(M_NRV2B_LE32, -1))
|
||||
e_method(M_NRV2B_LE32, opt->level);
|
||||
break;
|
||||
case 704:
|
||||
opt->method_nrv2d_seen = true;
|
||||
if (!set_method(M_NRV2D_LE32, -1))
|
||||
e_method(M_NRV2D_LE32, opt->level);
|
||||
break;
|
||||
case 705:
|
||||
opt->method_nrv2e_seen = true;
|
||||
if (!set_method(M_NRV2E_LE32, -1))
|
||||
e_method(M_NRV2E_LE32, opt->level);
|
||||
break;
|
||||
case 721:
|
||||
opt->method_lzma_seen = true;
|
||||
opt->all_methods_use_lzma = true;
|
||||
if (!set_method(M_LZMA, -1))
|
||||
e_method(M_LZMA, opt->level);
|
||||
break;
|
||||
case 722:
|
||||
opt->method_lzma_seen = false;
|
||||
opt->all_methods_use_lzma = false;
|
||||
if (M_IS_LZMA(opt->method))
|
||||
opt->method = -1;
|
||||
break;
|
||||
|
||||
// compression level
|
||||
case '1':
|
||||
@@ -532,6 +609,9 @@ static int do_option(int optc, const char *arg)
|
||||
e_method(opt->method, optc);
|
||||
break;
|
||||
|
||||
case 902: // --ultra-brute
|
||||
opt->ultra_brute = true;
|
||||
/* fallthrough */
|
||||
case 901: // --brute
|
||||
opt->all_methods = true;
|
||||
opt->all_methods_use_lzma = true;
|
||||
@@ -561,6 +641,20 @@ static int do_option(int optc, const char *arg)
|
||||
e_optarg(arg);
|
||||
opt->debug.dump_stub_loader = mfx_optarg;
|
||||
break;
|
||||
case 545:
|
||||
opt->debug.disable_random_id = true;
|
||||
break;
|
||||
|
||||
// mp (meta)
|
||||
case 501:
|
||||
getoptvar(&opt->mp_compress_task, 1, 999999, arg);
|
||||
break;
|
||||
case 502:
|
||||
opt->mp_query_format = true;
|
||||
break;
|
||||
case 503:
|
||||
opt->mp_query_num_tasks = true;
|
||||
break;
|
||||
|
||||
// misc
|
||||
case 512:
|
||||
@@ -578,6 +672,15 @@ static int do_option(int optc, const char *arg)
|
||||
case 519:
|
||||
opt->no_env = true;
|
||||
break;
|
||||
case 526:
|
||||
opt->preserve_mode = false;
|
||||
break;
|
||||
case 527:
|
||||
opt->preserve_ownership = false;
|
||||
break;
|
||||
case 528:
|
||||
opt->preserve_timestamp = false;
|
||||
break;
|
||||
// compression settings
|
||||
case 520: // --small
|
||||
if (opt->small < 0)
|
||||
@@ -585,7 +688,7 @@ static int do_option(int optc, const char *arg)
|
||||
opt->small++;
|
||||
break;
|
||||
case 521: // --filter=
|
||||
getoptvar(&opt->filter, 0, 255);
|
||||
getoptvar(&opt->filter, 0, 255, arg);
|
||||
opt->all_filters = false;
|
||||
break;
|
||||
case 522: // --no-filter
|
||||
@@ -599,37 +702,64 @@ static int do_option(int optc, const char *arg)
|
||||
break;
|
||||
case 524: // --all-methods
|
||||
opt->all_methods = true;
|
||||
opt->all_methods_use_lzma = true;
|
||||
opt->method = -1;
|
||||
break;
|
||||
case 525: // --exact
|
||||
opt->exact = true;
|
||||
break;
|
||||
// compression runtime parameters
|
||||
case 531:
|
||||
getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3);
|
||||
case 801:
|
||||
getoptvar(&opt->crp.crp_ucl.c_flags, 0, 3, arg);
|
||||
break;
|
||||
case 532:
|
||||
getoptvar(&opt->crp.crp_ucl.s_level, 0, 2);
|
||||
case 802:
|
||||
getoptvar(&opt->crp.crp_ucl.s_level, 0, 2, arg);
|
||||
break;
|
||||
case 533:
|
||||
getoptvar(&opt->crp.crp_ucl.h_level, 0, 1);
|
||||
case 803:
|
||||
getoptvar(&opt->crp.crp_ucl.h_level, 0, 1, arg);
|
||||
break;
|
||||
case 534:
|
||||
getoptvar(&opt->crp.crp_ucl.p_level, 0, 7);
|
||||
case 804:
|
||||
getoptvar(&opt->crp.crp_ucl.p_level, 0, 7, arg);
|
||||
break;
|
||||
case 535:
|
||||
getoptvar(&opt->crp.crp_ucl.max_offset, 256u, ~0u);
|
||||
case 805:
|
||||
getoptvar(&opt->crp.crp_ucl.max_offset, 256u, ~0u, arg);
|
||||
break;
|
||||
case 536:
|
||||
getoptvar(&opt->crp.crp_ucl.max_match, 16u, ~0u);
|
||||
case 806:
|
||||
getoptvar(&opt->crp.crp_ucl.max_match, 16u, ~0u, arg);
|
||||
break;
|
||||
case 537:
|
||||
if (getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u) != 0)
|
||||
e_optval("--crp-ms=");
|
||||
case 807:
|
||||
getoptvar(&opt->crp.crp_ucl.m_size, 10000u, 999999u, arg);
|
||||
break;
|
||||
case 811:
|
||||
getoptvar(&opt->crp.crp_lzma.pos_bits, arg);
|
||||
break;
|
||||
case 812:
|
||||
getoptvar(&opt->crp.crp_lzma.lit_pos_bits, arg);
|
||||
break;
|
||||
case 813:
|
||||
getoptvar(&opt->crp.crp_lzma.lit_context_bits, arg);
|
||||
break;
|
||||
case 814:
|
||||
getoptvar(&opt->crp.crp_lzma.dict_size, arg);
|
||||
break;
|
||||
case 816:
|
||||
getoptvar(&opt->crp.crp_lzma.num_fast_bytes, arg);
|
||||
break;
|
||||
case 821:
|
||||
getoptvar(&opt->crp.crp_zlib.mem_level, arg);
|
||||
break;
|
||||
case 822:
|
||||
getoptvar(&opt->crp.crp_zlib.window_bits, arg);
|
||||
break;
|
||||
case 823:
|
||||
getoptvar(&opt->crp.crp_zlib.strategy, arg);
|
||||
break;
|
||||
// backup
|
||||
case 'k':
|
||||
opt->backup = 1;
|
||||
break;
|
||||
case 541:
|
||||
if (opt->backup != 1) // do not overide `--backup'
|
||||
if (opt->backup != 1) // do not overide '--backup'
|
||||
opt->backup = 0;
|
||||
break;
|
||||
// overlay
|
||||
@@ -687,18 +817,20 @@ static int do_option(int optc, const char *arg)
|
||||
break;
|
||||
case 630:
|
||||
opt->win32_pe.compress_exports = 1;
|
||||
getoptvar(&opt->win32_pe.compress_exports, 0, 1);
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
getoptvar(&opt->win32_pe.compress_exports, 0, 1, arg);
|
||||
//printf("compress_exports: %d\n", opt->win32_pe.compress_exports);
|
||||
break;
|
||||
case 631:
|
||||
opt->win32_pe.compress_icons = 1;
|
||||
getoptvar(&opt->win32_pe.compress_icons, 0, 2);
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
getoptvar(&opt->win32_pe.compress_icons, 0, 3, arg);
|
||||
//printf("compress_icons: %d\n", opt->win32_pe.compress_icons);
|
||||
break;
|
||||
case 632:
|
||||
opt->win32_pe.compress_resources = true;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->win32_pe.compress_resources = false;
|
||||
opt->win32_pe.compress_resources = 1;
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
getoptvar(&opt->win32_pe.compress_resources, 0, 1, arg);
|
||||
//printf("compress_resources: %d\n", opt->win32_pe.compress_resources);
|
||||
break;
|
||||
case 633:
|
||||
@@ -706,8 +838,8 @@ static int do_option(int optc, const char *arg)
|
||||
break;
|
||||
case 634:
|
||||
opt->win32_pe.strip_relocs = 1;
|
||||
if (mfx_optarg && strcmp(mfx_optarg,"0") == 0)
|
||||
opt->win32_pe.strip_relocs = 0;
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
getoptvar(&opt->win32_pe.strip_relocs, 0, 1, arg);
|
||||
//printf("strip_relocs: %d\n", opt->win32_pe.strip_relocs);
|
||||
break;
|
||||
case 635:
|
||||
@@ -719,7 +851,7 @@ static int do_option(int optc, const char *arg)
|
||||
opt->atari_tos.split_segments = true;
|
||||
break;
|
||||
case 660:
|
||||
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u);
|
||||
getoptvar(&opt->o_unix.blocksize, 8192u, ~0u, arg);
|
||||
break;
|
||||
case 661:
|
||||
opt->o_unix.force_execve = true;
|
||||
@@ -727,7 +859,7 @@ static int do_option(int optc, const char *arg)
|
||||
case 662:
|
||||
opt->o_unix.script_name = "/usr/local/lib/upx/upxX";
|
||||
if (mfx_optarg && mfx_optarg[0])
|
||||
set_script_name(mfx_optarg,1);
|
||||
set_script_name(mfx_optarg, 1);
|
||||
break;
|
||||
case 663:
|
||||
opt->o_unix.is_ptinterp = true;
|
||||
@@ -761,7 +893,13 @@ static int do_option(int optc, const char *arg)
|
||||
opt->ps1_exe.do_8bit = true;
|
||||
break;
|
||||
case 673:
|
||||
opt->ps1_exe.do_8mb = false;
|
||||
opt->ps1_exe.do_8mib = false;
|
||||
break;
|
||||
case 674:
|
||||
opt->o_unix.unmap_all_pages = true; // val ?
|
||||
break;
|
||||
case 675:
|
||||
opt->o_unix.preserve_build_id = true;
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
@@ -769,7 +907,7 @@ static int do_option(int optc, const char *arg)
|
||||
case ':':
|
||||
return -2;
|
||||
default:
|
||||
fprintf(stderr,"%s: internal error in getopt (%d)\n",argv0,optc);
|
||||
fprintf(stderr,"%s: internal error in getopt (%d)\n", argv0, optc);
|
||||
return -3;
|
||||
}
|
||||
|
||||
@@ -786,10 +924,11 @@ static const struct mfx_option longopts[] =
|
||||
// commands
|
||||
{"best", 0x10, 0, 900}, // compress best
|
||||
{"brute", 0x10, 0, 901}, // compress best, brute force
|
||||
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force
|
||||
{"decompress", 0, 0, 'd'}, // decompress
|
||||
{"fast", 0x10, 0, '1'}, // compress faster
|
||||
{"fileinfo", 0x10, 0, 902}, // display info about file
|
||||
{"file-info", 0x10, 0, 902}, // display info about file
|
||||
{"fileinfo", 0x10, 0, 909}, // display info about file
|
||||
{"file-info", 0x10, 0, 909}, // display info about file
|
||||
{"help", 0, 0, 'h'+256}, // give help
|
||||
{"license", 0, 0, 'L'}, // display software license
|
||||
{"list", 0, 0, 'l'}, // list compressed exe
|
||||
@@ -802,7 +941,10 @@ static const struct mfx_option longopts[] =
|
||||
{"force-compress", 0, 0, 'f'}, // and compression of suspicious files
|
||||
{"info", 0, 0, 'i'}, // info mode
|
||||
{"no-env", 0x10, 0, 519}, // no environment var
|
||||
{"no-mode", 0x10, 0, 526}, // do not preserve mode (permissions)
|
||||
{"no-owner", 0x10, 0, 527}, // do not preserve ownership
|
||||
{"no-progress", 0, 0, 516}, // no progress bar
|
||||
{"no-time", 0x10, 0, 528}, // do not preserve timestamp
|
||||
{"output", 0x21, 0, 'o'},
|
||||
{"quiet", 0, 0, 'q'}, // quiet mode
|
||||
{"silent", 0, 0, 'q'}, // quiet mode
|
||||
@@ -818,18 +960,19 @@ static const struct mfx_option longopts[] =
|
||||
{"dump-stub-loader" ,0x31, 0, 544}, // for internal debugging
|
||||
{"fake-stub-version",0x31, 0, 542}, // for internal debugging
|
||||
{"fake-stub-year" ,0x31, 0, 543}, // for internal debugging
|
||||
{"disable-random-id",0x10, 0, 545}, // for internal debugging
|
||||
|
||||
// backup options
|
||||
{"backup", 0, 0, 'k'},
|
||||
{"keep", 0, 0, 'k'},
|
||||
{"no-backup", 0, 0, 541},
|
||||
{"backup", 0x10, 0, 'k'},
|
||||
{"keep", 0x10, 0, 'k'},
|
||||
{"no-backup", 0x10, 0, 541},
|
||||
|
||||
// overlay options
|
||||
{"overlay", 0x31, 0, 551}, // --overlay=
|
||||
{"skip-overlay", 0, 0, 552},
|
||||
{"no-overlay", 0, 0, 552}, // old name
|
||||
{"copy-overlay", 0, 0, 553},
|
||||
{"strip-overlay", 0, 0, 554},
|
||||
{"skip-overlay", 0x10, 0, 552},
|
||||
{"no-overlay", 0x10, 0, 552}, // old name
|
||||
{"copy-overlay", 0x10, 0, 553},
|
||||
{"strip-overlay", 0x10, 0, 554},
|
||||
|
||||
// CPU options
|
||||
{"cpu", 0x31, 0, 560}, // --cpu=
|
||||
@@ -838,34 +981,53 @@ static const struct mfx_option longopts[] =
|
||||
{"486", 0x10, 0, 564},
|
||||
|
||||
// color options
|
||||
{"no-color", 0, 0, 512},
|
||||
{"mono", 0, 0, 513},
|
||||
{"color", 0, 0, 514},
|
||||
{"no-color", 0x10, 0, 512},
|
||||
{"mono", 0x10, 0, 513},
|
||||
{"color", 0x10, 0, 514},
|
||||
|
||||
// compression method
|
||||
{"nrv2b", 0x10, 0, 702}, // --nrv2b
|
||||
{"nrv2d", 0x10, 0, 704}, // --nrv2d
|
||||
{"nrv2e", 0x10, 0, 705}, // --nrv2e
|
||||
{"lzma", 0x10, 0, 721}, // --lzma
|
||||
{"no-lzma", 0x10, 0, 722}, // (disable all_methods_use_lzma)
|
||||
// compression settings
|
||||
{"all-filters", 0x10, 0, 523},
|
||||
{"all-methods", 0x10, 0, 524},
|
||||
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression
|
||||
{"filter", 0x31, 0, 521}, // --filter=
|
||||
{"no-filter", 0x10, 0, 522},
|
||||
{"small", 0x10, 0, 520},
|
||||
// compression runtime parameters
|
||||
{"crp-cf", 0x31, 0, 531},
|
||||
{"crp-sl", 0x31, 0, 532},
|
||||
{"crp-hl", 0x31, 0, 533},
|
||||
{"crp-pl", 0x31, 0, 534},
|
||||
{"crp-mo", 0x31, 0, 535},
|
||||
{"crp-mm", 0x31, 0, 536},
|
||||
{"crp-ms", 0x31, 0, 537},
|
||||
{"crp-nrv-cf", 0x31, 0, 801},
|
||||
{"crp-nrv-sl", 0x31, 0, 802},
|
||||
{"crp-nrv-hl", 0x31, 0, 803},
|
||||
{"crp-nrv-pl", 0x31, 0, 804},
|
||||
{"crp-nrv-mo", 0x31, 0, 805},
|
||||
{"crp-nrv-mm", 0x31, 0, 806},
|
||||
{"crp-nrv-ms", 0x31, 0, 807},
|
||||
{"crp-ucl-cf", 0x31, 0, 801},
|
||||
{"crp-ucl-sl", 0x31, 0, 802},
|
||||
{"crp-ucl-hl", 0x31, 0, 803},
|
||||
{"crp-ucl-pl", 0x31, 0, 804},
|
||||
{"crp-ucl-mo", 0x31, 0, 805},
|
||||
{"crp-ucl-mm", 0x31, 0, 806},
|
||||
{"crp-ucl-ms", 0x31, 0, 807},
|
||||
{"crp-lzma-pb", 0x31, 0, 811},
|
||||
{"crp-lzma-lp", 0x31, 0, 812},
|
||||
{"crp-lzma-lc", 0x31, 0, 813},
|
||||
{"crp-lzma-ds", 0x31, 0, 814},
|
||||
{"crp-lzma-fb", 0x31, 0, 816},
|
||||
{"crp-zlib-ml", 0x31, 0, 821},
|
||||
{"crp-zlib-wb", 0x31, 0, 822},
|
||||
{"crp-zlib-st", 0x31, 0, 823},
|
||||
// [deprecated - only for compatibility with UPX 2.0x]
|
||||
{"crp-ms", 0x31, 0, 807},
|
||||
|
||||
// atari/tos
|
||||
{"split-segments", 0x10, 0, 650},
|
||||
// djgpp2/coff
|
||||
{"coff", 0, 0, 610}, // produce COFF output
|
||||
{"coff", 0x10, 0, 610}, // produce COFF output
|
||||
// dos/com
|
||||
// dos/exe
|
||||
//{"force-stub", 0x10, 0, 600},
|
||||
@@ -877,15 +1039,21 @@ static const struct mfx_option longopts[] =
|
||||
#if 0
|
||||
{"script", 0x31, 0, 662}, // --script=
|
||||
#endif
|
||||
{"is_ptinterp", 0, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"use_ptinterp", 0, 0, 664}, // linux/elf386 PT_INTERP program
|
||||
{"make_ptinterp", 0, 0, 665}, // linux/elf386 PT_INTERP program
|
||||
{"Linux", 0, 0, 666},
|
||||
{"FreeBSD", 0, 0, 667},
|
||||
{"NetBSD", 0, 0, 668},
|
||||
{"OpenBSD", 0, 0, 669},
|
||||
{"is_ptinterp", 0x10, 0, 663}, // linux/elf386 PT_INTERP program
|
||||
{"use_ptinterp", 0x10, 0, 664}, // linux/elf386 PT_INTERP program
|
||||
{"make_ptinterp", 0x10, 0, 665}, // linux/elf386 PT_INTERP program
|
||||
{"Linux", 0x10, 0, 666},
|
||||
{"linux", 0x10, 0, 666},
|
||||
{"FreeBSD", 0x10, 0, 667},
|
||||
{"freebsd", 0x10, 0, 667},
|
||||
{"NetBSD", 0x10, 0, 668},
|
||||
{"netbsd", 0x10, 0, 668},
|
||||
{"OpenBSD", 0x10, 0, 669},
|
||||
{"openbsd", 0x10, 0, 669},
|
||||
{"unmap-all-pages", 0x10, 0, 674}, // linux /proc/self/exe vanishes
|
||||
{"preserve-build-id", 0, 0, 675},
|
||||
// watcom/le
|
||||
{"le", 0, 0, 620}, // produce LE output
|
||||
{"le", 0x10, 0, 620}, // produce LE output
|
||||
// win32/pe
|
||||
{"compress-exports", 2, 0, 630},
|
||||
{"compress-icons", 2, 0, 631},
|
||||
@@ -897,19 +1065,26 @@ static const struct mfx_option longopts[] =
|
||||
{"boot-only", 0x10, 0, 670},
|
||||
{"no-align", 0x10, 0, 671},
|
||||
{"8-bit", 0x10, 0, 672},
|
||||
{"8mib-ram", 0x10, 0, 673},
|
||||
{"8mb-ram", 0x10, 0, 673},
|
||||
|
||||
// mp (meta) options
|
||||
{"mp-compress-task", 0x31, 0, 501},
|
||||
{"mp-query-format", 0x10, 0, 502},
|
||||
{"mp-query-num-tasks", 0x10, 0, 503},
|
||||
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int optc, longind;
|
||||
char buf[256];
|
||||
char shortopts[256];
|
||||
|
||||
prepare_shortopts(buf,"123456789hH?V",longopts),
|
||||
mfx_optind = 0;
|
||||
mfx_opterr = 1;
|
||||
prepare_shortopts(shortopts, "123456789hH?V", longopts),
|
||||
acc_getopt_init(&mfx_getopt, 1, argc, argv);
|
||||
mfx_getopt.progname = progname;
|
||||
mfx_getopt.opterr = handle_opterr;
|
||||
opt->o_unix.osabi0 = Elf32_Ehdr::ELFOSABI_LINUX;
|
||||
while ((optc = mfx_getopt_long(argc, argv, buf, longopts, &longind)) >= 0)
|
||||
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
|
||||
{
|
||||
if (do_option(optc, argv[mfx_optind-1]) != 0)
|
||||
e_usage();
|
||||
@@ -930,6 +1105,7 @@ static const struct mfx_option longopts[] =
|
||||
// commands
|
||||
{"best", 0x10, 0, 900}, // compress best
|
||||
{"brute", 0x10, 0, 901}, // compress best, brute force
|
||||
{"ultra-brute", 0x10, 0, 902}, // compress best, brute force
|
||||
{"fast", 0x10, 0, '1'}, // compress faster
|
||||
|
||||
// options
|
||||
@@ -939,17 +1115,20 @@ static const struct mfx_option longopts[] =
|
||||
{"silent", 0, 0, 'q'}, // quiet mode
|
||||
{"verbose", 0, 0, 'v'}, // verbose mode
|
||||
|
||||
// debug options
|
||||
{"disable-random-id",0x10, 0, 545}, // for internal debugging
|
||||
|
||||
// backup options
|
||||
{"backup", 0, 0, 'k'},
|
||||
{"keep", 0, 0, 'k'},
|
||||
{"backup", 0x10, 0, 'k'},
|
||||
{"keep", 0x10, 0, 'k'},
|
||||
{"no-backup", 0x10, 0, 541},
|
||||
|
||||
// overlay options
|
||||
{"overlay", 0x31, 0, 551}, // --overlay=
|
||||
{"skip-overlay", 0, 0, 552},
|
||||
{"no-overlay", 0, 0, 552}, // old name
|
||||
{"copy-overlay", 0, 0, 553},
|
||||
{"strip-overlay", 0, 0, 554},
|
||||
{"skip-overlay", 0x10, 0, 552},
|
||||
{"no-overlay", 0x10, 0, 552}, // old name
|
||||
{"copy-overlay", 0x10, 0, 553},
|
||||
{"strip-overlay", 0x10, 0, 554},
|
||||
|
||||
// CPU options
|
||||
{"cpu", 0x31, 0, 560}, // --cpu=
|
||||
@@ -958,18 +1137,21 @@ static const struct mfx_option longopts[] =
|
||||
{"486", 0x10, 0, 564},
|
||||
|
||||
// color options
|
||||
{"no-color", 0, 0, 512},
|
||||
{"mono", 0, 0, 513},
|
||||
{"color", 0, 0, 514},
|
||||
{"no-color", 0x10, 0, 512},
|
||||
{"mono", 0x10, 0, 513},
|
||||
{"color", 0x10, 0, 514},
|
||||
|
||||
// compression settings
|
||||
{"exact", 0x10, 0, 525}, // user requires byte-identical decompression
|
||||
|
||||
// compression method
|
||||
{"nrv2b", 0x10, 0, 702}, // --nrv2b
|
||||
{"nrv2d", 0x10, 0, 704}, // --nrv2d
|
||||
{"nrv2e", 0x10, 0, 705}, // --nrv2e
|
||||
{"lzma", 0x10, 0, 721}, // --lzma
|
||||
{"no-lzma", 0x10, 0, 722}, // (disable all_methods_use_lzma)
|
||||
// compression settings
|
||||
// compression runtime parameters
|
||||
{"crp-cf", 0x31, 0, 531},
|
||||
{"crp-sl", 0x31, 0, 532},
|
||||
{"crp-hl", 0x31, 0, 533},
|
||||
{"crp-pl", 0x31, 0, 534},
|
||||
{"crp-mo", 0x31, 0, 535},
|
||||
{"crp-mm", 0x31, 0, 536},
|
||||
{"crp-ms", 0x31, 0, 537},
|
||||
|
||||
// win32/pe
|
||||
{"compress-exports", 2, 0, 630},
|
||||
@@ -988,7 +1170,7 @@ static const struct mfx_option longopts[] =
|
||||
int targc;
|
||||
char **targv = NULL;
|
||||
static const char sep[] = " \t";
|
||||
char buf[256];
|
||||
char shortopts[256];
|
||||
|
||||
var = getenv(OPTIONS_VAR);
|
||||
if (var == NULL || !var[0])
|
||||
@@ -1044,10 +1226,11 @@ static const struct mfx_option longopts[] =
|
||||
e_envopt(targv[i]);
|
||||
|
||||
/* handle options */
|
||||
prepare_shortopts(buf,"123456789",longopts);
|
||||
mfx_optind = 0;
|
||||
mfx_opterr = 1;
|
||||
while ((optc = mfx_getopt_long(targc, targv, buf, longopts, &longind)) >= 0)
|
||||
prepare_shortopts(shortopts, "123456789", longopts);
|
||||
acc_getopt_init(&mfx_getopt, 1, targc, targv);
|
||||
mfx_getopt.progname = progname;
|
||||
mfx_getopt.opterr = handle_opterr;
|
||||
while ((optc = acc_getopt(&mfx_getopt, shortopts, longopts, &longind)) >= 0)
|
||||
{
|
||||
if (do_option(optc, targv[mfx_optind-1]) != 0)
|
||||
e_envopt(NULL);
|
||||
@@ -1093,9 +1276,33 @@ static void first_options(int argc, char **argv)
|
||||
**************************************************************************/
|
||||
|
||||
template <class T> struct TestBELE {
|
||||
static int test(void)
|
||||
static bool test(void)
|
||||
{
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(T)
|
||||
__packed_struct(test1_t) char a; T b; __packed_struct_end()
|
||||
__packed_struct(test2_t) char a; T b[3]; __packed_struct_end()
|
||||
test1_t t1[7]; UNUSED(t1); test2_t t2[7]; UNUSED(t2);
|
||||
COMPILE_TIME_ASSERT(sizeof(test1_t) == 1 + sizeof(T))
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(test1_t)
|
||||
COMPILE_TIME_ASSERT(sizeof(t1) == 7 + 7*sizeof(T))
|
||||
COMPILE_TIME_ASSERT(sizeof(test2_t) == 1 + 3*sizeof(T))
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(test2_t)
|
||||
COMPILE_TIME_ASSERT(sizeof(t2) == 7 + 21*sizeof(T))
|
||||
#if defined(__acc_alignof)
|
||||
#if (ACC_CC_CLANG && ACC_ARCH_AMD64)
|
||||
// CBUG: clang-2.8 bug in 64-bit mode
|
||||
#else
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t1) == 1)
|
||||
COMPILE_TIME_ASSERT(__acc_alignof(t2) == 1)
|
||||
#endif
|
||||
#endif
|
||||
#if 1 && (ACC_CC_WATCOMC)
|
||||
test1_t t11; COMPILE_TIME_ASSERT(sizeof(t11.a) <= sizeof(t11.b))
|
||||
test2_t t22; COMPILE_TIME_ASSERT(sizeof(t22.a) <= sizeof(t22.b))
|
||||
#endif
|
||||
#if 1 && !defined(UPX_OFFICIAL_BUILD)
|
||||
T allbits; allbits = 0; allbits -= 1;
|
||||
//++allbits; allbits++; --allbits; allbits--;
|
||||
T v1; v1 = 1; v1 *= 2; v1 -= 1;
|
||||
T v2; v2 = 1;
|
||||
assert( (v1 == v2)); assert(!(v1 != v2));
|
||||
@@ -1109,7 +1316,9 @@ static int test(void)
|
||||
assert(v1 == 1); assert(v2 == 0);
|
||||
v1 <<= 1; v1 |= v2; v1 >>= 1; v2 &= v1; v2 /= v1; v2 *= v1;
|
||||
assert(v1 == 1); assert(v2 == 0);
|
||||
return (v1 ^ v2) == 1;
|
||||
if ((v1 ^ v2) != 1) return false;
|
||||
#endif
|
||||
return true;
|
||||
}};
|
||||
|
||||
|
||||
@@ -1141,12 +1350,12 @@ void upx_sanity_check(void)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE32) == 4)
|
||||
COMPILE_TIME_ASSERT(sizeof(LE64) == 8)
|
||||
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(BE64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE16, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE32, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(LE64, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(BE16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(BE32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(BE64)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(LE16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(LE32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(LE64)
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(UPX_VERSION_STRING4) == 4 + 1)
|
||||
assert(strlen(UPX_VERSION_STRING4) == 4);
|
||||
@@ -1157,37 +1366,49 @@ void upx_sanity_check(void)
|
||||
assert(memcmp(UPX_VERSION_DATE + strlen(UPX_VERSION_DATE) - 4, UPX_VERSION_YEAR, 4) == 0);
|
||||
|
||||
#if 1
|
||||
# if 1 && !defined(UPX_OFFICIAL_BUILD)
|
||||
assert(TestBELE<LE16>::test());
|
||||
assert(TestBELE<LE32>::test());
|
||||
assert(TestBELE<LE64>::test());
|
||||
assert(TestBELE<BE16>::test());
|
||||
assert(TestBELE<BE32>::test());
|
||||
assert(TestBELE<BE64>::test());
|
||||
# endif
|
||||
{
|
||||
static const unsigned char dd[32] = { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
static const unsigned char dd[32]
|
||||
#if 1 && (ACC_CC_CLANG || ACC_CC_GNUC || ACC_CC_INTELC || ACC_CC_PATHSCALE) && defined(__ELF__)
|
||||
__attribute__((__aligned__(16)))
|
||||
#endif
|
||||
= { 0, 0, 0, 0, 0, 0, 0,
|
||||
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
|
||||
0, 0, 0, 0,
|
||||
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||
0, 0, 0, 0, 0 };
|
||||
const unsigned char *d;
|
||||
const N_BELE_RTP::AbstractPolicy *bele;
|
||||
d = dd + 7;
|
||||
assert(upx_adler32(d, 4) == 0x09f003f7);
|
||||
assert(upx_adler32(d, 4, 0) == 0x09ec03f6);
|
||||
assert(upx_adler32(d, 4, 1) == 0x09f003f7);
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
assert(get_be16(d) == 0xfffe);
|
||||
assert(bele->get16(d) == 0xfffe);
|
||||
assert(get_be16_signed(d) == -2);
|
||||
assert(get_be24(d) == 0xfffefd);
|
||||
assert(bele->get24(d) == 0xfffefd);
|
||||
assert(get_be24_signed(d) == -259);
|
||||
assert(get_be32(d) == 0xfffefdfc);
|
||||
assert(bele->get32(d) == 0xfffefdfc);
|
||||
assert(get_be32_signed(d) == -66052);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
assert(get_le16(d) == 0xfeff);
|
||||
assert(bele->get16(d) == 0xfeff);
|
||||
assert(get_le16_signed(d) == -257);
|
||||
assert(get_le24(d) == 0xfdfeff);
|
||||
assert(bele->get24(d) == 0xfdfeff);
|
||||
assert(get_le24_signed(d) == -131329);
|
||||
assert(get_le32(d) == 0xfcfdfeff);
|
||||
assert(bele->get32(d) == 0xfcfdfeff);
|
||||
assert(get_le32_signed(d) == -50462977);
|
||||
assert(get_le64_signed(d) == UPX_INT64_C(-506097522914230529));
|
||||
assert(find_be16(d, 2, 0xfffe) == 0);
|
||||
assert(find_le16(d, 2, 0xfeff) == 0);
|
||||
assert(find_be32(d, 4, 0xfffefdfc) == 0);
|
||||
@@ -1196,6 +1417,7 @@ void upx_sanity_check(void)
|
||||
assert(get_be16_signed(d) == 32638);
|
||||
assert(get_be24_signed(d) == 8355453);
|
||||
assert(get_be32_signed(d) == 2138996092);
|
||||
assert(get_be64_signed(d) == UPX_INT64_C(9186918263483431288));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1205,7 +1427,11 @@ void upx_sanity_check(void)
|
||||
// main entry point
|
||||
**************************************************************************/
|
||||
|
||||
#if !defined(WITH_GUI)
|
||||
#if !(WITH_GUI)
|
||||
|
||||
#if (ACC_ARCH_M68K && ACC_OS_TOS && ACC_CC_GNUC) && defined(__MINT__)
|
||||
extern "C" { extern long _stksize; long _stksize = 256 * 1024L; }
|
||||
#endif
|
||||
|
||||
int __acc_cdecl_main main(int argc, char *argv[])
|
||||
{
|
||||
@@ -1216,11 +1442,14 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
#if 0 && defined(__DJGPP__)
|
||||
// LFN=n may cause problems with 2.03's _rename and mkdir under WinME
|
||||
putenv("LFN=y");
|
||||
#endif
|
||||
#if (ACC_OS_WIN32 || ACC_OS_WIN64) && (ACC_CC_MSC) && defined(_WRITE_ABORT_MSG) && defined(_CALL_REPORTFAULT)
|
||||
_set_abort_behavior(_WRITE_ABORT_MSG, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
#endif
|
||||
acc_wildargv(&argc, &argv);
|
||||
|
||||
upx_sanity_check();
|
||||
init_options(opt);
|
||||
opt->reset();
|
||||
|
||||
if (!argv[0] || !argv[0][0])
|
||||
argv[0] = default_argv0;
|
||||
@@ -1251,7 +1480,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
|
||||
set_term(stderr);
|
||||
|
||||
#if defined(WITH_UCL)
|
||||
#if (WITH_UCL)
|
||||
if (ucl_init() != UCL_E_OK)
|
||||
{
|
||||
show_head();
|
||||
@@ -1262,7 +1491,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
e_exit(EXIT_INIT);
|
||||
}
|
||||
#endif
|
||||
#if defined(WITH_NRV)
|
||||
#if (WITH_NRV)
|
||||
if (nrv_init() != NRV_E_OK || NRV_VERSION != nrv_version())
|
||||
{
|
||||
show_head();
|
||||
@@ -1321,14 +1550,6 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
if (opt->cmd != CMD_COMPRESS)
|
||||
{
|
||||
// invalidate compression options
|
||||
opt->method = 0;
|
||||
opt->level = 0;
|
||||
memset(&opt->crp, 0xff, sizeof(opt->crp));
|
||||
}
|
||||
|
||||
/* check options */
|
||||
if (argc == 1)
|
||||
e_help();
|
||||
@@ -1347,7 +1568,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
set_term(stdout);
|
||||
do_files(i,argc,argv);
|
||||
|
||||
#if 0 && (UPX_VERSION_HEX < 0x020000)
|
||||
#if 0 && (UPX_VERSION_HEX < 0x030000)
|
||||
{
|
||||
FILE *f = stdout;
|
||||
int fg = con_fg(f,FG_RED);
|
||||
@@ -1363,7 +1584,7 @@ int __acc_cdecl_main main(int argc, char *argv[])
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
#endif /* !defined(WITH_GUI) */
|
||||
#endif /* !(WITH_GUI) */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+8
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ static int mcheck_init()
|
||||
if (use_mcheck < 0)
|
||||
{
|
||||
use_mcheck = 1;
|
||||
#if defined(WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||
#if (WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND)
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
{
|
||||
//fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n");
|
||||
@@ -154,7 +154,7 @@ void MemBuffer::fill(unsigned off, unsigned len, int value)
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#define PTR(p) ((unsigned) ((acc_uintptr_t)(p) & 0xffffffff))
|
||||
#define PTR(p) ((unsigned) ((upx_uintptr_t)(p) & 0xffffffff))
|
||||
#define MAGIC1(p) (PTR(p) ^ 0xfefdbeeb)
|
||||
#define MAGIC2(p) (PTR(p) ^ 0xfefdbeeb ^ 0x80024001)
|
||||
|
||||
@@ -192,11 +192,7 @@ void MemBuffer::alloc(unsigned size)
|
||||
assert((int)total > 0);
|
||||
unsigned char *p = (unsigned char *) malloc(total);
|
||||
if (!p)
|
||||
{
|
||||
//throw bad_alloc();
|
||||
throw OutOfMemoryException("out of memory");
|
||||
//exit(1);
|
||||
}
|
||||
throwOutOfMemoryException();
|
||||
b_size = size;
|
||||
if (use_mcheck)
|
||||
{
|
||||
@@ -209,6 +205,8 @@ void MemBuffer::alloc(unsigned size)
|
||||
}
|
||||
else
|
||||
b = p ;
|
||||
|
||||
//fill(0, b_size, (rand() & 0xff) | 1); // debug
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_MEM_H
|
||||
#define __UPX_MEM_H
|
||||
#define __UPX_MEM_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -38,7 +38,7 @@ class MemBuffer
|
||||
{
|
||||
public:
|
||||
MemBuffer();
|
||||
MemBuffer(unsigned size);
|
||||
explicit MemBuffer(unsigned size);
|
||||
~MemBuffer();
|
||||
|
||||
static unsigned getSizeForCompression(unsigned uncompressed_size, unsigned extra=0);
|
||||
|
||||
+2283
-1653
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ void printClearLine(FILE *f)
|
||||
fflush(stdout); fflush(stderr);
|
||||
if (f == NULL)
|
||||
f = stdout;
|
||||
con_fprintf(f,clear_line_msg);
|
||||
con_fprintf(f, "%s", clear_line_msg);
|
||||
fflush(f);
|
||||
printSetNl(0);
|
||||
}
|
||||
|
||||
@@ -1,706 +0,0 @@
|
||||
/* Getopt for GNU.
|
||||
NOTE: getopt is now part of the C library, so if you don't know what
|
||||
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
|
||||
before changing it!
|
||||
|
||||
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
|
||||
|
||||
#undef PROGNAME
|
||||
#if 0
|
||||
#ifndef EOF
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#define PROGNAME(x) (x)
|
||||
#else
|
||||
#include "conf.h"
|
||||
static const char *my_progname(const char *argv0)
|
||||
{
|
||||
return progname ? progname : argv0;
|
||||
}
|
||||
#define PROGNAME(x) my_progname(x)
|
||||
#endif
|
||||
|
||||
|
||||
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
|
||||
long-named option. Because this is not POSIX.2 compliant, it is
|
||||
being phased out. */
|
||||
/* #define GETOPT_COMPAT */
|
||||
#undef GETOPT_COMPAT
|
||||
|
||||
/* This version of `getopt' appears to the caller like standard Unix `getopt'
|
||||
but it behaves differently for the user, since it allows the user
|
||||
to intersperse the options with the other arguments.
|
||||
|
||||
As `getopt' works, it permutes the elements of ARGV so that,
|
||||
when it is done, all the options precede everything else. Thus
|
||||
all application programs are extended to handle flexible argument order.
|
||||
|
||||
Setting the environment variable POSIXLY_CORRECT disables permutation.
|
||||
Then the behavior is completely standard.
|
||||
|
||||
GNU application programs can use a third alternative mode in which
|
||||
they can distinguish the relative order of options and other arguments. */
|
||||
|
||||
#include "mygetopt.h"
|
||||
#define option mfx_option
|
||||
#define optarg mfx_optarg
|
||||
#define optind mfx_optind
|
||||
#define opterr mfx_opterr
|
||||
#define optopt mfx_optopt
|
||||
#undef BAD_OPTION
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
char *optarg = NULL;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
/* XXX 1003.2 says this must be 1 before any call. */
|
||||
int optind = 0;
|
||||
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
|
||||
static char *nextchar;
|
||||
|
||||
/* Callers store zero here to inhibit the error message
|
||||
for unrecognized options. */
|
||||
|
||||
int opterr = 1;
|
||||
|
||||
/* Set to an option character which was unrecognized.
|
||||
This must be initialized on some systems to avoid linking in the
|
||||
system's own getopt implementation. */
|
||||
|
||||
#define BAD_OPTION '\0'
|
||||
int optopt = BAD_OPTION;
|
||||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
If the caller did not specify anything,
|
||||
the default is REQUIRE_ORDER if the environment variable
|
||||
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options;
|
||||
stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
This mode of operation is selected by either setting the environment
|
||||
variable POSIXLY_CORRECT, or using `+' as the first character
|
||||
of the list of option characters.
|
||||
|
||||
PERMUTE is the default. We permute the contents of ARGV as we scan,
|
||||
so that eventually all the non-options are at the end. This allows options
|
||||
to be given in any order, even with programs that were not written to
|
||||
expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were written
|
||||
to expect options and other ARGV-elements in any order and that care about
|
||||
the ordering of the two. We describe each non-option ARGV-element
|
||||
as if it were the argument of an option with character code 1.
|
||||
Using `-' as the first character of the list of option characters
|
||||
selects this mode of operation.
|
||||
|
||||
The special argument `--' forces an end of option-scanning regardless
|
||||
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
|
||||
|
||||
static enum
|
||||
{
|
||||
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
|
||||
} ordering;
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
been skipped. `first_nonopt' is the index in ARGV of the first of them;
|
||||
`last_nonopt' is the index after the last of them. */
|
||||
|
||||
static int first_nonopt;
|
||||
static int last_nonopt;
|
||||
|
||||
/* Exchange two adjacent subsequences of ARGV.
|
||||
One subsequence is elements [first_nonopt,last_nonopt)
|
||||
which contains all the non-options that have been skipped so far.
|
||||
The other is elements [last_nonopt,optind), which contains all
|
||||
the options processed since those non-options were skipped.
|
||||
|
||||
`first_nonopt' and `last_nonopt' are relocated so that they describe
|
||||
the new indices of the non-options in ARGV after they are moved.
|
||||
|
||||
To perform the swap, we first reverse the order of all elements. So
|
||||
all options now come before all non options, but they are in the
|
||||
wrong order. So we put back the options and non options in original
|
||||
order by reversing them again. For example:
|
||||
original input: a b c -x -y
|
||||
reverse all: -y -x c b a
|
||||
reverse options: -x -y c b a
|
||||
reverse non options: -x -y a b c
|
||||
*/
|
||||
|
||||
|
||||
static void exchange (char **argv)
|
||||
{
|
||||
char *temp; char **first, **last;
|
||||
|
||||
/* Reverse all the elements [first_nonopt, optind) */
|
||||
first = &argv[first_nonopt];
|
||||
last = &argv[optind-1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
/* Put back the options in order */
|
||||
first = &argv[first_nonopt];
|
||||
first_nonopt += (optind - last_nonopt);
|
||||
last = &argv[first_nonopt - 1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
|
||||
/* Put back the non options in order */
|
||||
first = &argv[first_nonopt];
|
||||
last_nonopt = optind;
|
||||
last = &argv[last_nonopt-1];
|
||||
while (first < last) {
|
||||
temp = *first; *first = *last; *last = temp; first++; last--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan elements of ARGV (whose length is ARGC) for option characters
|
||||
given in OPTSTRING.
|
||||
|
||||
If an element of ARGV starts with '-', and is not exactly "-" or "--",
|
||||
then it is an option element. The characters of this element
|
||||
(aside from the initial '-') are option characters. If `getopt'
|
||||
is called repeatedly, it returns successively each of the option characters
|
||||
from each of the option elements.
|
||||
|
||||
If `getopt' finds another option character, it returns that character,
|
||||
updating `optind' and `nextchar' so that the next call to `getopt' can
|
||||
resume the scan with the following option character or ARGV-element.
|
||||
|
||||
If there are no more option characters, `getopt' returns `EOF'.
|
||||
Then `optind' is the index in ARGV of the first ARGV-element
|
||||
that is not an option. (The ARGV-elements have been permuted
|
||||
so that those that are not options now come last.)
|
||||
|
||||
OPTSTRING is a string containing the legitimate option characters.
|
||||
If an option character is seen that is not listed in OPTSTRING,
|
||||
return BAD_OPTION after printing an error message. If you set `opterr' to
|
||||
zero, the error message is suppressed but we still return BAD_OPTION.
|
||||
|
||||
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
|
||||
so the following text in the same ARGV-element, or the text of the following
|
||||
ARGV-element, is returned in `optarg'. Two colons mean an option that
|
||||
wants an optional arg; if there is text in the current ARGV-element,
|
||||
it is returned in `optarg', otherwise `optarg' is set to zero.
|
||||
|
||||
If OPTSTRING starts with `-' or `+', it requests different methods of
|
||||
handling the non-option ARGV-elements.
|
||||
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
|
||||
|
||||
Long-named options begin with `--' instead of `-'.
|
||||
Their names may be abbreviated as long as the abbreviation is unique
|
||||
or is an exact match for some defined option. If they have an
|
||||
argument, it follows the option name in the same ARGV-element, separated
|
||||
from the option name by a `=', or else the in next ARGV-element.
|
||||
When `getopt' finds a long-named option, it returns 0 if that option's
|
||||
`flag' field is nonzero, the value of the option's `val' field
|
||||
if the `flag' field is zero.
|
||||
|
||||
LONGOPTS is a vector of `struct option' terminated by an
|
||||
element containing a name which is zero.
|
||||
|
||||
LONGIND returns the index in LONGOPT of the long-named option found.
|
||||
It is only valid when a long-named option has been found by the most
|
||||
recent call.
|
||||
|
||||
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
|
||||
long-named options. */
|
||||
|
||||
static int _getopt_internal (int argc, char **argv, const char *optstring,
|
||||
const struct option *longopts, int *longind,
|
||||
int long_only)
|
||||
{
|
||||
static char empty_string[1];
|
||||
int option_index;
|
||||
|
||||
if (longind != NULL)
|
||||
*longind = -1;
|
||||
|
||||
optarg = 0;
|
||||
|
||||
/* Initialize the internal data when the first call is made.
|
||||
Start processing options with ARGV-element 1 (since ARGV-element 0
|
||||
is the program name); the sequence of previously skipped
|
||||
non-option ARGV-elements is empty. */
|
||||
|
||||
if (optind == 0)
|
||||
{
|
||||
first_nonopt = last_nonopt = optind = 1;
|
||||
|
||||
nextchar = NULL;
|
||||
|
||||
/* Determine how to handle the ordering of options and nonoptions. */
|
||||
|
||||
if (optstring[0] == '-')
|
||||
{
|
||||
ordering = RETURN_IN_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
else if (optstring[0] == '+')
|
||||
{
|
||||
ordering = REQUIRE_ORDER;
|
||||
++optstring;
|
||||
}
|
||||
#if 0
|
||||
else if (getenv ("POSIXLY_CORRECT") != NULL)
|
||||
ordering = REQUIRE_ORDER;
|
||||
#endif
|
||||
else
|
||||
ordering = PERMUTE;
|
||||
}
|
||||
|
||||
if (nextchar == NULL || *nextchar == '\0')
|
||||
{
|
||||
if (ordering == PERMUTE)
|
||||
{
|
||||
/* If we have just processed some options following some non-options,
|
||||
exchange them so that the options come first. */
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (argv);
|
||||
else if (last_nonopt != optind)
|
||||
first_nonopt = optind;
|
||||
|
||||
/* Now skip any additional non-options
|
||||
and extend the range of non-options previously skipped. */
|
||||
|
||||
while (optind < argc
|
||||
&& (argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
#ifdef GETOPT_COMPAT
|
||||
&& (longopts == NULL
|
||||
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||
#endif /* GETOPT_COMPAT */
|
||||
)
|
||||
optind++;
|
||||
last_nonopt = optind;
|
||||
}
|
||||
|
||||
/* Special ARGV-element `--' means premature end of options.
|
||||
Skip it like a null option,
|
||||
then exchange with previous non-options as if it were an option,
|
||||
then skip everything else like a non-option. */
|
||||
|
||||
if (optind != argc && !strcmp (argv[optind], "--"))
|
||||
{
|
||||
optind++;
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (argv);
|
||||
else if (first_nonopt == last_nonopt)
|
||||
first_nonopt = optind;
|
||||
last_nonopt = argc;
|
||||
|
||||
optind = argc;
|
||||
}
|
||||
|
||||
/* If we have done all the ARGV-elements, stop the scan
|
||||
and back over any non-options that we skipped and permuted. */
|
||||
|
||||
if (optind == argc)
|
||||
{
|
||||
/* Set the next-arg-index to point at the non-options
|
||||
that we previously skipped, so the caller will digest them. */
|
||||
if (first_nonopt != last_nonopt)
|
||||
optind = first_nonopt;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* If we have come to a non-option and did not permute it,
|
||||
either stop the scan or describe it to the caller and pass it by. */
|
||||
|
||||
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
|
||||
#ifdef GETOPT_COMPAT
|
||||
&& (longopts == NULL
|
||||
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
|
||||
#endif /* GETOPT_COMPAT */
|
||||
)
|
||||
{
|
||||
if (ordering == REQUIRE_ORDER)
|
||||
return EOF;
|
||||
optarg = argv[optind++];
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* We have found another option-ARGV-element.
|
||||
Start decoding its characters. */
|
||||
|
||||
nextchar = (argv[optind] + 1
|
||||
+ (longopts != NULL && argv[optind][1] == '-'));
|
||||
}
|
||||
|
||||
if (longopts != NULL
|
||||
&& ((argv[optind][0] == '-'
|
||||
&& (argv[optind][1] == '-' || long_only))
|
||||
#ifdef GETOPT_COMPAT
|
||||
|| argv[optind][0] == '+'
|
||||
#endif /* GETOPT_COMPAT */
|
||||
))
|
||||
{
|
||||
const struct option *p;
|
||||
char *s = nextchar;
|
||||
int exact = 0;
|
||||
int ambig = 0;
|
||||
const struct option *pfound = NULL;
|
||||
int indfound = 0;
|
||||
int needexact = 0;
|
||||
|
||||
/* allow `--option#value' because you cannout assign a '='
|
||||
to an environment variable under DOS command.com */
|
||||
while (*s && *s != '=' && * s != '#')
|
||||
s++;
|
||||
|
||||
/* Test all options for either exact match or abbreviated matches. */
|
||||
for (p = longopts, option_index = 0; p->name;
|
||||
p++, option_index++)
|
||||
if (!strncmp (p->name, nextchar, (unsigned) (s - nextchar)))
|
||||
{
|
||||
if (p->has_arg & 0x10)
|
||||
needexact = 1;
|
||||
if ((unsigned) (s - nextchar) == strlen (p->name))
|
||||
{
|
||||
/* Exact match found. */
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
exact = 1;
|
||||
break;
|
||||
}
|
||||
else if (pfound == NULL)
|
||||
{
|
||||
/* First nonexact match found. */
|
||||
pfound = p;
|
||||
indfound = option_index;
|
||||
}
|
||||
else
|
||||
/* Second nonexact match found. */
|
||||
ambig = 1;
|
||||
}
|
||||
|
||||
/* don't allow nonexact longoptions */
|
||||
if (needexact && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: unrecognized option `%s'\n",
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
if (ambig && !exact)
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `%s' is ambiguous\n",
|
||||
PROGNAME(argv[0]), argv[optind]);
|
||||
nextchar += strlen (nextchar);
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
|
||||
if (pfound != NULL)
|
||||
{
|
||||
int have_arg = (s[0] != '\0');
|
||||
if (have_arg && (pfound->has_arg & 0xf))
|
||||
have_arg = (s[1] != '\0');
|
||||
option_index = indfound;
|
||||
optind++;
|
||||
if (have_arg)
|
||||
{
|
||||
/* Don't test has_arg with >, because some C compilers don't
|
||||
allow it to be used on enums. */
|
||||
if (pfound->has_arg & 0xf)
|
||||
optarg = s + 1;
|
||||
else
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
if (argv[optind - 1][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr,
|
||||
"%s: option `--%s' doesn't allow an argument\n",
|
||||
PROGNAME(argv[0]), pfound->name);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr,
|
||||
"%s: option `%c%s' doesn't allow an argument\n",
|
||||
PROGNAME(argv[0]), argv[optind - 1][0], pfound->name);
|
||||
}
|
||||
nextchar += strlen (nextchar);
|
||||
return BAD_OPTION;
|
||||
}
|
||||
}
|
||||
else if ((pfound->has_arg & 0xf) == 1)
|
||||
{
|
||||
#if 0
|
||||
if (optind < argc)
|
||||
#else
|
||||
if (optind < argc && (pfound->has_arg & 0x20) == 0)
|
||||
#endif
|
||||
optarg = argv[optind++];
|
||||
else
|
||||
{
|
||||
if (opterr)
|
||||
fprintf (stderr, "%s: option `--%s%s' requires an argument\n",
|
||||
PROGNAME(argv[0]), pfound->name,
|
||||
(pfound->has_arg & 0x20) ? "=" : "");
|
||||
nextchar += strlen (nextchar);
|
||||
return optstring[0] == ':' ? ':' : BAD_OPTION;
|
||||
}
|
||||
}
|
||||
nextchar += strlen (nextchar);
|
||||
if (longind != NULL)
|
||||
*longind = option_index;
|
||||
if (pfound->flag)
|
||||
{
|
||||
*(pfound->flag) = pfound->val;
|
||||
return 0;
|
||||
}
|
||||
return pfound->val;
|
||||
}
|
||||
/* Can't find it as a long option. If this is not getopt_long_only,
|
||||
or the option starts with '--' or is not a valid short
|
||||
option, then it's an error.
|
||||
Otherwise interpret it as a short option. */
|
||||
if (!long_only || argv[optind][1] == '-'
|
||||
#ifdef GETOPT_COMPAT
|
||||
|| argv[optind][0] == '+'
|
||||
#endif /* GETOPT_COMPAT */
|
||||
|| strchr (optstring, *nextchar) == NULL)
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
if (argv[optind][1] == '-')
|
||||
/* --option */
|
||||
fprintf (stderr, "%s: unrecognized option `--%s'\n",
|
||||
PROGNAME(argv[0]), nextchar);
|
||||
else
|
||||
/* +option or -option */
|
||||
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
|
||||
PROGNAME(argv[0]), argv[optind][0], nextchar);
|
||||
}
|
||||
nextchar = empty_string;
|
||||
optind++;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
(void) &ambig; /* UNUSED */
|
||||
}
|
||||
|
||||
/* Look at and handle the next option-character. */
|
||||
|
||||
{
|
||||
char c = *nextchar++;
|
||||
const char *temp = strchr (optstring, c);
|
||||
|
||||
/* Increment `optind' when we start to process its last character. */
|
||||
if (*nextchar == '\0')
|
||||
++optind;
|
||||
|
||||
if (temp == NULL || c == ':')
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
#if 0
|
||||
if (c < 040 || c >= 0177)
|
||||
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
else
|
||||
fprintf (stderr, "%s: unrecognized option `-%c'\n", PROGNAME(argv[0]), c);
|
||||
#else
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, "%s: illegal option -- %c\n", PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
return BAD_OPTION;
|
||||
}
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (temp[2] == ':')
|
||||
{
|
||||
/* This is an option that accepts an argument optionally. */
|
||||
if (*nextchar != '\0')
|
||||
{
|
||||
optarg = nextchar;
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
optarg = 0;
|
||||
nextchar = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an option that requires an argument. */
|
||||
if (*nextchar != '\0')
|
||||
{
|
||||
optarg = nextchar;
|
||||
/* If we end this ARGV-element by taking the rest as an arg,
|
||||
we must advance to the next element now. */
|
||||
optind++;
|
||||
}
|
||||
else if (optind == argc)
|
||||
{
|
||||
if (opterr)
|
||||
{
|
||||
#if 0
|
||||
fprintf (stderr, "%s: option `-%c' requires an argument\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
#else
|
||||
/* 1003.2 specifies the format of this message. */
|
||||
fprintf (stderr, "%s: option requires an argument -- %c\n",
|
||||
PROGNAME(argv[0]), c);
|
||||
#endif
|
||||
}
|
||||
optopt = c;
|
||||
if (optstring[0] == ':')
|
||||
c = ':';
|
||||
else
|
||||
c = BAD_OPTION;
|
||||
}
|
||||
else
|
||||
/* We already incremented `optind' once;
|
||||
increment it again when taking next ARGV-elt as argument. */
|
||||
optarg = argv[optind++];
|
||||
nextchar = NULL;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int mfx_getopt(int argc, char **argv, const char *optstring)
|
||||
{
|
||||
return _getopt_internal (argc, argv, optstring,
|
||||
(const struct option *) 0,
|
||||
(int *) 0,
|
||||
0);
|
||||
}
|
||||
|
||||
int mfx_getopt_long(int argc, char **argv, const char *options,
|
||||
const struct option *long_options, int *opt_index)
|
||||
{
|
||||
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
/* Compile with -DTEST to make an executable for use in testing
|
||||
the above definition of `getopt'. */
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
|
||||
c = getopt (argc, argv, "abc:d:0123456789");
|
||||
if (c == EOF)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind)
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf ("option c with value `%s'\n", optarg);
|
||||
break;
|
||||
|
||||
case BAD_OPTION:
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc)
|
||||
printf ("%s ", argv[optind++]);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et:nowrap
|
||||
*/
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef __MFX_GETOPT_H
|
||||
#define __MFX_GETOPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* extern "C" { */
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *mfx_optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int mfx_optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int mfx_opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int mfx_optopt;
|
||||
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct mfx_option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
#define mfx_no_argument 0
|
||||
#define mfx_required_argument 1
|
||||
#define mfx_optional_argument 2
|
||||
#define mfx_exact_argument 0x10 /* no abbrev. */
|
||||
|
||||
int mfx_getopt(int argc, char **argv, const char *shortopts);
|
||||
int mfx_getopt_long(int argc, char **argv, const char *shortopts,
|
||||
const struct mfx_option *longopts, int *longind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* } */
|
||||
#endif
|
||||
|
||||
#endif /* __MFX_GETOPT_H */
|
||||
+29
-30
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_OPTIONS_H
|
||||
#define __UPX_OPTIONS_H
|
||||
#define __UPX_OPTIONS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,14 +45,25 @@ enum {
|
||||
struct options_t {
|
||||
int cmd;
|
||||
|
||||
// mp (meta) options
|
||||
int mp_compress_task;
|
||||
bool mp_query_format;
|
||||
bool mp_query_num_tasks;
|
||||
|
||||
// compression options
|
||||
int method;
|
||||
bool method_lzma_seen;
|
||||
bool method_nrv2b_seen;
|
||||
bool method_nrv2d_seen;
|
||||
bool method_nrv2e_seen;
|
||||
int level; // compression level 1..10
|
||||
int filter; // preferred filter from Packer::getFilters()
|
||||
bool ultra_brute;
|
||||
bool all_methods; // try all available compression methods ?
|
||||
bool all_methods_use_lzma;
|
||||
bool all_filters; // try all available filters ?
|
||||
bool no_filter; // force no filter
|
||||
bool exact; // user requires byte-identical decompression
|
||||
|
||||
// other options
|
||||
int backup;
|
||||
@@ -63,6 +74,9 @@ struct options_t {
|
||||
bool no_env;
|
||||
bool no_progress;
|
||||
const char *output_name;
|
||||
bool preserve_mode;
|
||||
bool preserve_ownership;
|
||||
bool preserve_timestamp;
|
||||
int small;
|
||||
int verbose;
|
||||
bool to_stdout;
|
||||
@@ -70,6 +84,7 @@ struct options_t {
|
||||
// debug options
|
||||
struct {
|
||||
int debug_level;
|
||||
bool disable_random_id; // for Packer::getRandomId()
|
||||
const char *dump_stub_loader;
|
||||
char fake_stub_version[4+1]; // for internal debugging
|
||||
char fake_stub_year[4+1]; // for internal debugging
|
||||
@@ -83,32 +98,12 @@ struct options_t {
|
||||
};
|
||||
int overlay;
|
||||
|
||||
// compression runtime parameters - see struct ucl_compress_config_t
|
||||
struct crp_lzma_t {
|
||||
int dummy;
|
||||
#if 0
|
||||
unsigned pos_bits; // pb
|
||||
unsigned lit_pos_bits; // lp
|
||||
unsigned lit_context_bits; // lc
|
||||
unsigned dict_size;
|
||||
unsigned mf_passes;
|
||||
#endif
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
struct crp_ucl_t {
|
||||
unsigned max_offset;
|
||||
unsigned max_match;
|
||||
int s_level;
|
||||
int h_level;
|
||||
int p_level;
|
||||
int c_flags;
|
||||
unsigned m_size;
|
||||
void reset() { memset(this, 0xff, sizeof(*this)); }
|
||||
};
|
||||
// compression runtime parameters - see struct XXX_compress_config_t
|
||||
struct crp_t {
|
||||
crp_lzma_t crp_lzma;
|
||||
crp_ucl_t crp_ucl;
|
||||
void reset() { crp_lzma.reset(); crp_ucl.reset(); }
|
||||
lzma_compress_config_t crp_lzma;
|
||||
ucl_compress_config_t crp_ucl;
|
||||
zlib_compress_config_t crp_zlib;
|
||||
void reset() { crp_lzma.reset(); crp_ucl.reset(); crp_zlib.reset(); }
|
||||
};
|
||||
crp_t crp;
|
||||
|
||||
@@ -139,7 +134,7 @@ struct options_t {
|
||||
bool boot_only;
|
||||
bool no_align;
|
||||
bool do_8bit;
|
||||
bool do_8mb;
|
||||
bool do_8mib;
|
||||
} ps1_exe;
|
||||
struct {
|
||||
unsigned blocksize;
|
||||
@@ -147,9 +142,11 @@ struct options_t {
|
||||
bool is_ptinterp; // is PT_INTERP, so don't adjust auxv_t
|
||||
bool use_ptinterp; // use PT_INTERP /opt/upx/run
|
||||
bool make_ptinterp; // make PT_INTERP [ignore current file!]
|
||||
bool unmap_all_pages; // thus /proc/self/exe vanishes
|
||||
unsigned char osabi0; // replacement if 0==.e_ident[EI_OSABI]
|
||||
enum { SCRIPT_MAX = 32 };
|
||||
const char *script_name;
|
||||
bool preserve_build_id; // copy the build-id to the compressed binary
|
||||
} o_unix;
|
||||
struct {
|
||||
bool le;
|
||||
@@ -162,6 +159,8 @@ struct options_t {
|
||||
int strip_relocs;
|
||||
const char *keep_resource;
|
||||
} win32_pe;
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
extern struct options_t *opt;
|
||||
|
||||
+87
-68
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -115,26 +115,25 @@ PackArmPe::~PackArmPe()
|
||||
|
||||
const int *PackArmPe::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
static const int m_nrv2b[] = { M_NRV2B_8, M_NRV2E_8, M_LZMA, M_END };
|
||||
static const int m_nrv2e[] = { M_NRV2E_8, M_NRV2B_8, M_LZMA, M_END };
|
||||
static const int m_all[] = { M_NRV2B_8, M_NRV2E_8, M_LZMA, M_END };
|
||||
static const int m_lzma[] = { M_LZMA, M_END };
|
||||
static const int m_nrv2b[] = { M_NRV2B_8, M_END };
|
||||
static const int m_nrv2e[] = { M_NRV2E_8, M_END };
|
||||
|
||||
if (!use_thumb_stub)
|
||||
return getDefaultCompressionMethods_8(method, level);
|
||||
|
||||
if (M_IS_NRV2B(method))
|
||||
return m_nrv2b;
|
||||
if (M_IS_NRV2E(method))
|
||||
return m_nrv2e;
|
||||
if (M_IS_LZMA(method))
|
||||
return m_lzma;
|
||||
if (method == M_ALL) return m_all;
|
||||
if (M_IS_LZMA(method)) return m_lzma;
|
||||
if (M_IS_NRV2B(method)) return m_nrv2b;
|
||||
if (M_IS_NRV2E(method)) return m_nrv2e;
|
||||
return m_nrv2e;
|
||||
}
|
||||
|
||||
|
||||
const int *PackArmPe::getFilters() const
|
||||
{
|
||||
static const int filters[] = { 0x50, -1 };
|
||||
static const int filters[] = { 0x50, FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
@@ -149,14 +148,12 @@ Linker* PackArmPe::newLinker() const
|
||||
// import handling
|
||||
**************************************************************************/
|
||||
|
||||
struct import_desc
|
||||
{
|
||||
__packed_struct(import_desc)
|
||||
LE32 oft; // orig first thunk
|
||||
char _[8];
|
||||
LE32 dllname;
|
||||
LE32 iat; // import address table
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
void PackArmPe::processImports(unsigned myimport, unsigned iat_off) // pass 2
|
||||
{
|
||||
@@ -205,6 +202,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
unsigned iat;
|
||||
LE32 *lookupt;
|
||||
unsigned npos;
|
||||
unsigned original_position;
|
||||
bool isk32;
|
||||
|
||||
static int __acc_cdecl_qsort compare(const void *p1, const void *p2)
|
||||
@@ -213,6 +211,8 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
const udll *u2 = * (const udll * const *) p2;
|
||||
if (u1->isk32) return -1;
|
||||
if (u2->isk32) return 1;
|
||||
if (!*u1->lookupt) return 1;
|
||||
if (!*u2->lookupt) return -1;
|
||||
int rc = strcasecmp(u1->name,u2->name);
|
||||
if (rc) return rc;
|
||||
if (u1->ordinal) return -1;
|
||||
@@ -239,11 +239,12 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
dlls[ic].iat = im->iat;
|
||||
dlls[ic].lookupt = (LE32*) (ibuf + (im->oft ? im->oft : im->iat));
|
||||
dlls[ic].npos = 0;
|
||||
dlls[ic].original_position = ic;
|
||||
dlls[ic].isk32 = strcasecmp(kernel32dll,dlls[ic].name) == 0;
|
||||
|
||||
soimport += strlen(dlls[ic].name) + 1 + 4;
|
||||
|
||||
for (LE32 *tarr = dlls[ic].lookupt; *tarr; tarr++)
|
||||
for (IPTR_I(LE32, tarr, dlls[ic].lookupt); *tarr; tarr += 1)
|
||||
{
|
||||
if (*tarr & 0x80000000)
|
||||
{
|
||||
@@ -255,10 +256,11 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned len = strlen(ibuf + *tarr + 2);
|
||||
IPTR_I(const upx_byte, n, ibuf + *tarr + 2);
|
||||
unsigned len = strlen(n);
|
||||
soimport += len + 1;
|
||||
if (dlls[ic].shname == NULL || len < strlen (dlls[ic].shname))
|
||||
dlls[ic].shname = ibuf + *tarr + 2;
|
||||
dlls[ic].shname = n;
|
||||
}
|
||||
soimport++; // separator
|
||||
}
|
||||
@@ -292,7 +294,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
|
||||
unsigned k32namepos = ptr_diff(dllnames,oimpdlls);
|
||||
|
||||
memcpy(importednames, llgpa, ALIGN_UP(sizeof(llgpa), 2));
|
||||
memcpy(importednames, llgpa, ALIGN_UP((unsigned) sizeof(llgpa), 2u));
|
||||
strcpy(dllnames,kernel32dll);
|
||||
im->dllname = k32namepos;
|
||||
im->iat = ptr_diff(ordinals,oimpdlls);
|
||||
@@ -346,8 +348,10 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++)
|
||||
{
|
||||
LE32 *tarr = idlls[ic]->lookupt;
|
||||
#if 0 && ENABLE_THIS_AND_UNCOMPRESSION_WILL_BREAK
|
||||
if (!*tarr) // no imports from this dll
|
||||
continue;
|
||||
#endif
|
||||
set_le32(ppi,idlls[ic]->npos);
|
||||
set_le32(ppi+4,idlls[ic]->iat - rvamin);
|
||||
ppi += 8;
|
||||
@@ -415,7 +419,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
for (ic = 0; ic < dllnum; ic++, im++)
|
||||
{
|
||||
memset(im,FILLVAL,sizeof(*im));
|
||||
im->dllname = ptr_diff(idlls[ic]->name,ibuf); // I only need this info
|
||||
im->dllname = ptr_diff(dlls[idlls[ic]->original_position].name,ibuf);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -440,7 +444,7 @@ unsigned PackArmPe::processImports() // pass 1
|
||||
|
||||
void PackArmPe::processTls(Interval *) // pass 1
|
||||
{
|
||||
if ((sotls = ALIGN_UP(IDSIZE(PEDIR_TLS),4)) == 0)
|
||||
if ((sotls = ALIGN_UP(IDSIZE(PEDIR_TLS),4u)) == 0)
|
||||
return;
|
||||
|
||||
// never should happen on wince
|
||||
@@ -462,10 +466,10 @@ bool PackArmPe::canPack()
|
||||
}
|
||||
|
||||
|
||||
int PackArmPe::buildLoader(const Filter *ft)
|
||||
void PackArmPe::buildLoader(const Filter *ft)
|
||||
{
|
||||
const unsigned char *loader = use_thumb_stub ? nrv_loader_thumb : nrv_loader_arm;
|
||||
unsigned size = use_thumb_stub ? sizeof(nrv_loader_thumb) : sizeof(nrv_loader_arm);
|
||||
const unsigned char *loader = use_thumb_stub ? stub_arm_v4t_wince_pe : stub_arm_v4a_wince_pe;
|
||||
unsigned size = use_thumb_stub ? sizeof(stub_arm_v4t_wince_pe) : sizeof(stub_arm_v4a_wince_pe);
|
||||
|
||||
// prepare loader
|
||||
initLoader(loader, size);
|
||||
@@ -503,13 +507,15 @@ int PackArmPe::buildLoader(const Filter *ft)
|
||||
addLoader("+40C,LZMA_DECODE,LZMA_DEC10", NULL);
|
||||
|
||||
addLoader("IDENTSTR,UPX1HEAD", NULL);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
void PackArmPe::pack(OutputFile *fo)
|
||||
{
|
||||
// FIXME: we need to think about better support for --exact
|
||||
if (opt->exact)
|
||||
throwCantPackExact();
|
||||
|
||||
const unsigned objs = ih.objects;
|
||||
isection = new pe_section_t[objs];
|
||||
fi->seek(pe_offset+sizeof(ih),SEEK_SET);
|
||||
@@ -545,10 +551,12 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
else if (opt->win32_pe.strip_relocs < 0)
|
||||
opt->win32_pe.strip_relocs = (ih.imagebase >= 0x10000);
|
||||
if (opt->win32_pe.strip_relocs)
|
||||
{
|
||||
if (ih.imagebase < 0x10000)
|
||||
throwCantPack("--strip-relocs is not allowed when imagebase < 0x10000");
|
||||
else
|
||||
ih.flags |= RELOCS_STRIPPED;
|
||||
}
|
||||
|
||||
if (memcmp(isection[0].name,"UPX",3) == 0)
|
||||
throwAlreadyPackedByUPX();
|
||||
@@ -557,7 +565,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
if (ih.entry && ih.entry < rvamin)
|
||||
throwCantPack("run a virus scanner on this file!");
|
||||
if (!opt->force && ih.subsystem == 1)
|
||||
throwCantPack("subsystem `native' is not supported (try --force)");
|
||||
throwCantPack("subsystem 'native' is not supported (try --force)");
|
||||
if (ih.filealign < 0x200)
|
||||
throwCantPack("filealign < 0x200 is not yet supported");
|
||||
|
||||
@@ -591,7 +599,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
if (((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED))
|
||||
== (PEFL_WRITE|PEFL_SHARED)))
|
||||
if (!opt->force)
|
||||
throwCantPack("writeable shared sections not supported (try --force)");
|
||||
throwCantPack("writable shared sections not supported (try --force)");
|
||||
if (jc && isection[ic].rawdataptr - jc > ih.filealign)
|
||||
throwCantPack("superfluous data between sections");
|
||||
fi->seek(isection[ic].rawdataptr,SEEK_SET);
|
||||
@@ -635,7 +643,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
|
||||
//OutputFile::dump("x1", ibuf, usize);
|
||||
|
||||
// some checks for broken linkers - disable filter if neccessary
|
||||
// some checks for broken linkers - disable filter if necessary
|
||||
bool allow_filter = true;
|
||||
if (ih.codebase == ih.database
|
||||
|| ih.codebase + ih.codesize > ih.imagesize
|
||||
@@ -700,20 +708,20 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
ft.buf_len = ih.codesize;
|
||||
ft.addvalue = ih.codebase - rvamin;
|
||||
// compress
|
||||
int strategy = allow_filter ? 0 : -3;
|
||||
int filter_strategy = allow_filter ? 0 : -3;
|
||||
|
||||
// disable filters for files with broken headers
|
||||
if (ih.codebase + ih.codesize > ph.u_len)
|
||||
{
|
||||
ft.buf_len = 1;
|
||||
strategy = -3;
|
||||
filter_strategy = -3;
|
||||
}
|
||||
|
||||
// limit stack size needed for runtime decompression
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, 2048, strategy,
|
||||
NULL, &cconf, ih.codebase, rvamin);
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 2048, &cconf, filter_strategy,
|
||||
ih.codebase, rvamin, 0, NULL, 0);
|
||||
// info: see buildLoader()
|
||||
newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1;
|
||||
/*
|
||||
@@ -729,13 +737,11 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
getLoaderSection("UPX1HEAD",(int*)&ic);
|
||||
identsize += ic;
|
||||
|
||||
pe_section_t osection[3];
|
||||
pe_section_t osection[4];
|
||||
// section 0 : bss
|
||||
// 1 : [ident + header] + packed_data + unpacker + tls
|
||||
// 2 : not compressed data
|
||||
|
||||
// section 2 should start with the resource data, because lots of lame
|
||||
// windoze codes assume that resources starts on the beginning of a section
|
||||
// 3 : resource data -- wince 5 needs a new section for this
|
||||
|
||||
// identsplit - number of ident + (upx header) bytes to put into the PE header
|
||||
int identsplit = pe_offset + sizeof(osection) + sizeof(oh);
|
||||
@@ -750,7 +756,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
const unsigned c_len = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15);
|
||||
obuf.clear(ph.c_len, c_len - ph.c_len);
|
||||
|
||||
const unsigned s1size = ALIGN_UP(ic + c_len + codesize,4) + sotls;
|
||||
const unsigned s1size = ALIGN_UP(ic + c_len + codesize,4u) + sotls;
|
||||
const unsigned s1addr = (newvsize - (ic + c_len) + oam1) &~ oam1;
|
||||
|
||||
const unsigned ncsection = (s1addr + s1size + oam1) &~ oam1;
|
||||
@@ -773,7 +779,7 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
memset(osection,0,sizeof(osection));
|
||||
|
||||
oh.entry = upxsection;
|
||||
oh.objects = 3;
|
||||
oh.objects = 4;
|
||||
oh.chksum = 0;
|
||||
|
||||
// fill the data directory
|
||||
@@ -802,12 +808,6 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
ODSIZE(PEDIR_RELOC) = soxrelocs;
|
||||
ic += soxrelocs;
|
||||
|
||||
if (soresources)
|
||||
processResources(&res,ic);
|
||||
ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0;
|
||||
ODSIZE(PEDIR_RESOURCE) = soresources;
|
||||
ic += soresources;
|
||||
|
||||
processImports(ic, linker->getSymbolOffset("IATT") + upxsection);
|
||||
ODADDR(PEDIR_IMPORT) = ic;
|
||||
ODSIZE(PEDIR_IMPORT) = soimpdlls;
|
||||
@@ -823,7 +823,15 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
}
|
||||
ic += soexport;
|
||||
|
||||
const unsigned onam = ncsection + soxrelocs + soresources + ih.imagebase;
|
||||
ic = (ic + oam1) &~ oam1;
|
||||
const unsigned res_start = ic;
|
||||
if (soresources)
|
||||
processResources(&res,ic);
|
||||
ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0;
|
||||
ODSIZE(PEDIR_RESOURCE) = soresources;
|
||||
ic += soresources;
|
||||
|
||||
const unsigned onam = ncsection + soxrelocs + ih.imagebase;
|
||||
linker->defineSymbol("start_of_dll_names", onam);
|
||||
linker->defineSymbol("start_of_imports", ih.imagebase + rvamin + cimports);
|
||||
linker->defineSymbol("start_of_relocs", crelocs + rvamin + ih.imagebase);
|
||||
@@ -835,58 +843,58 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
linker->defineSymbol("compressed_length", ph.c_len);
|
||||
linker->defineSymbol("start_of_compressed", ih.imagebase + s1addr + identsize - identsplit);
|
||||
defineDecompressorSymbols();
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader, lsize);
|
||||
|
||||
// this is computed here, because soxrelocs changes some lines above
|
||||
const unsigned ncsize = soxrelocs + soresources + soimpdlls + soexport;
|
||||
const unsigned ncsize = soxrelocs + soimpdlls + soexport;
|
||||
const unsigned fam1 = oh.filealign - 1;
|
||||
|
||||
// fill the sections
|
||||
strcpy(osection[0].name,"UPX0");
|
||||
strcpy(osection[1].name,"UPX1");
|
||||
// after some windoze debugging I found that the name of the sections
|
||||
// DOES matter :( .rsrc is used by oleaut32.dll (TYPELIBS)
|
||||
// and because of this lame dll, the resource stuff must be the
|
||||
// first in the 3rd section - the author of this dll seems to be
|
||||
// too idiot to use the data directories... M$ suxx 4 ever!
|
||||
// ... even worse: exploder.exe in NiceTry also depends on this to
|
||||
// locate version info
|
||||
|
||||
strcpy(osection[2].name,soresources ? ".rsrc" : "UPX2");
|
||||
strcpy(osection[2].name, "UPX2");
|
||||
strcpy(osection[3].name, ".rsrc");
|
||||
|
||||
osection[0].vaddr = rvamin;
|
||||
osection[1].vaddr = s1addr;
|
||||
osection[2].vaddr = ncsection;
|
||||
osection[3].vaddr = res_start;
|
||||
|
||||
osection[0].size = 0;
|
||||
osection[1].size = (s1size + fam1) &~ fam1;
|
||||
osection[2].size = (ncsize + fam1) &~ fam1;
|
||||
osection[3].size = (soresources + fam1) &~ fam1;
|
||||
|
||||
osection[0].vsize = osection[1].vaddr - osection[0].vaddr;
|
||||
//osection[1].vsize = (osection[1].size + oam1) &~ oam1;
|
||||
//osection[2].vsize = (osection[2].size + oam1) &~ oam1;
|
||||
osection[1].vsize = osection[1].size;
|
||||
osection[2].vsize = osection[2].size;
|
||||
osection[3].vsize = osection[3].size;
|
||||
|
||||
osection[0].rawdataptr = 0;
|
||||
osection[1].rawdataptr = (pe_offset + sizeof(oh) + sizeof(osection) + fam1) &~ fam1;
|
||||
osection[2].rawdataptr = osection[1].rawdataptr + osection[1].size;
|
||||
osection[3].rawdataptr = osection[2].rawdataptr + osection[2].size;
|
||||
|
||||
osection[0].flags = (unsigned) (PEFL_BSS|PEFL_EXEC|PEFL_WRITE|PEFL_READ);
|
||||
osection[1].flags = (unsigned) (PEFL_DATA|PEFL_EXEC|PEFL_WRITE|PEFL_READ);
|
||||
osection[2].flags = (unsigned) (PEFL_DATA|PEFL_READ);
|
||||
osection[3].flags = (unsigned) (PEFL_DATA|PEFL_READ);
|
||||
|
||||
oh.imagesize = (osection[2].vaddr + osection[2].vsize + oam1) &~ oam1;
|
||||
oh.imagesize = (osection[3].vaddr + osection[3].vsize + oam1) &~ oam1;
|
||||
oh.bsssize = osection[0].vsize;
|
||||
oh.datasize = osection[2].vsize;
|
||||
oh.datasize = osection[2].vsize + osection[3].vsize;
|
||||
oh.database = osection[2].vaddr;
|
||||
oh.codesize = osection[1].vsize;
|
||||
oh.codebase = osection[1].vaddr;
|
||||
oh.headersize = osection[1].rawdataptr;
|
||||
if (rvamin < osection[0].rawdataptr)
|
||||
throwCantPack("object alignment too small");
|
||||
|
||||
if (opt->win32_pe.strip_relocs && !isdll)
|
||||
oh.flags |= RELOCS_STRIPPED;
|
||||
@@ -895,11 +903,16 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
// set_le32(ibuf + ic,get_le32("UPX "));
|
||||
ibuf.clear(0, oh.filealign);
|
||||
|
||||
info("Image size change: %u -> %u kBytes",
|
||||
info("Image size change: %u -> %u KiB",
|
||||
ih.imagesize / 1024, oh.imagesize / 1024);
|
||||
|
||||
infoHeader("[Writing compressed file]");
|
||||
|
||||
if (soresources == 0)
|
||||
{
|
||||
oh.objects = 3;
|
||||
memset(&osection[3], 0, sizeof(osection[3]));
|
||||
}
|
||||
// write loader + compressed file
|
||||
fo->write(&oh,sizeof(oh));
|
||||
fo->write(osection,sizeof(osection));
|
||||
@@ -920,14 +933,17 @@ void PackArmPe::pack(OutputFile *fo)
|
||||
if ((ic = fo->getBytesWritten() & 3) != 0)
|
||||
fo->write(ibuf,4 - ic);
|
||||
fo->write(otls,sotls);
|
||||
if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0)
|
||||
if ((ic = fo->getBytesWritten() & fam1) != 0)
|
||||
fo->write(ibuf,oh.filealign - ic);
|
||||
fo->write(oxrelocs,soxrelocs);
|
||||
fo->write(oresources,soresources);
|
||||
fo->write(oimpdlls,soimpdlls);
|
||||
fo->write(oexport,soexport);
|
||||
|
||||
if ((ic = fo->getBytesWritten() & (oh.filealign-1)) != 0)
|
||||
if ((ic = fo->getBytesWritten() & fam1) != 0)
|
||||
fo->write(ibuf,oh.filealign - ic);
|
||||
|
||||
fo->write(oresources,soresources);
|
||||
if ((ic = fo->getBytesWritten() & fam1) != 0)
|
||||
fo->write(ibuf,oh.filealign - ic);
|
||||
|
||||
#if 0
|
||||
@@ -970,7 +986,7 @@ int PackArmPe::canUnpack()
|
||||
fi->readx(isection,sizeof(pe_section_t)*objs);
|
||||
if (ih.objects < 3)
|
||||
return -1;
|
||||
bool is_packed = (ih.objects == 3 &&
|
||||
bool is_packed = ((ih.objects == 3 || ih.objects == 4) &&
|
||||
(IDSIZE(15) || ih.entry > isection[1].vaddr));
|
||||
bool found_ph = false;
|
||||
if (memcmp(isection[0].name,"UPX",3) == 0)
|
||||
@@ -1024,7 +1040,8 @@ int PackArmPe::canUnpack()
|
||||
|
||||
void PackArmPe::rebuildImports(upx_byte *& extrainfo)
|
||||
{
|
||||
if (ODADDR(PEDIR_IMPORT) == 0)
|
||||
if (ODADDR(PEDIR_IMPORT) == 0
|
||||
|| ODSIZE(PEDIR_IMPORT) <= sizeof(import_desc))
|
||||
return;
|
||||
|
||||
// const upx_byte * const idata = obuf + get_le32(extrainfo);
|
||||
@@ -1042,6 +1059,7 @@ void PackArmPe::rebuildImports(upx_byte *& extrainfo)
|
||||
for (p = idata; get_le32(p) != 0; ++p)
|
||||
{
|
||||
const upx_byte *dname = get_le32(p) + import;
|
||||
ICHECK(dname, 1);
|
||||
const unsigned dlen = strlen(dname);
|
||||
ICHECK(dname, dlen + 1);
|
||||
|
||||
@@ -1054,7 +1072,7 @@ void PackArmPe::rebuildImports(upx_byte *& extrainfo)
|
||||
else
|
||||
p += 5;
|
||||
}
|
||||
sdllnames = ALIGN_UP(sdllnames,2);
|
||||
sdllnames = ALIGN_UP(sdllnames,2u);
|
||||
|
||||
upx_byte * const Obuf = obuf - rvamin;
|
||||
import_desc * const im0 = (import_desc*) (Obuf + ODADDR(PEDIR_IMPORT));
|
||||
@@ -1067,6 +1085,7 @@ void PackArmPe::rebuildImports(upx_byte *& extrainfo)
|
||||
{
|
||||
// restore the name of the dll
|
||||
const upx_byte *dname = get_le32(p) + import;
|
||||
ICHECK(dname, 1);
|
||||
const unsigned dlen = strlen(dname);
|
||||
ICHECK(dname, dlen + 1);
|
||||
|
||||
|
||||
+9
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,14 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H
|
||||
#define __UPX_P_ARMPE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// arm/pe
|
||||
@@ -39,9 +40,10 @@ class PackArmPe : public PeFile
|
||||
|
||||
public:
|
||||
PackArmPe(InputFile *f);
|
||||
~PackArmPe();
|
||||
virtual ~PackArmPe();
|
||||
virtual int getFormat() const { return UPX_F_WINCE_ARM_PE; }
|
||||
virtual const char *getName() const { return "arm/pe"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "arm-wince.pe"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -51,7 +53,7 @@ public:
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
virtual unsigned processImports();
|
||||
|
||||
+16
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
static const
|
||||
#include "stub/i086-dos16.com.h"
|
||||
|
||||
//#define TESTING
|
||||
//#define TESTING 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -45,16 +45,11 @@ static const
|
||||
|
||||
const int *PackCom::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
static const int m_nrv2b[] = { M_NRV2B_LE16, -1 };
|
||||
if (M_IS_NRV2B(method))
|
||||
return m_nrv2b;
|
||||
static const int m_nrv2b[] = { M_NRV2B_LE16, M_END };
|
||||
#if 0
|
||||
// NOT IMPLEMENTED
|
||||
static const int m_nrv2d[] = { M_NRV2D_LE16, -1 };
|
||||
if (M_IS_NRV2D(method))
|
||||
return m_nrv2d;
|
||||
static const int m_nrv2d[] = { M_NRV2D_LE16, M_END };
|
||||
#endif
|
||||
UNUSED(level);
|
||||
UNUSED(method); UNUSED(level);
|
||||
return m_nrv2b;
|
||||
}
|
||||
|
||||
@@ -63,7 +58,7 @@ const int *PackCom::getFilters() const
|
||||
{
|
||||
static const int filters[] = {
|
||||
0x06, 0x03, 0x04, 0x01, 0x05, 0x02,
|
||||
-1 };
|
||||
FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
@@ -101,7 +96,7 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
{
|
||||
const int e_len = getLoaderSectionStart("COMCUTPO");
|
||||
const int d_len = lsize - e_len;
|
||||
assert(e_len > 0 && e_len < 256);
|
||||
assert(e_len > 0 && e_len < 128);
|
||||
assert(d_len > 0 && d_len < 256);
|
||||
|
||||
const unsigned upper_end = ph.u_len + ph.overlap_overhead + d_len + 0x100;
|
||||
@@ -116,9 +111,10 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
linker->defineSymbol("bytes_to_copy", ph.c_len + lsize);
|
||||
linker->defineSymbol("copy_source", ph.c_len + lsize + 0x100);
|
||||
linker->defineSymbol("copy_destination", upper_end);
|
||||
linker->defineSymbol("COMCUTPO", ph.u_len + ph.overlap_overhead);
|
||||
linker->defineSymbol("neg_e_len", 0 - e_len);
|
||||
linker->defineSymbol("NRV2B160", ph.u_len + ph.overlap_overhead);
|
||||
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
loader = getLoader();
|
||||
|
||||
// some day we could use the relocation stuff for patchPackHeader too
|
||||
@@ -135,9 +131,9 @@ void PackCom::patchLoader(OutputFile *fo,
|
||||
}
|
||||
|
||||
|
||||
int PackCom::buildLoader(const Filter *ft)
|
||||
void PackCom::buildLoader(const Filter *ft)
|
||||
{
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
initLoader(stub_i086_dos16_com, sizeof(stub_i086_dos16_com));
|
||||
addLoader("COMMAIN1",
|
||||
ph.first_offset_found == 1 ? "COMSBBBP" : "",
|
||||
"COMPSHDI",
|
||||
@@ -154,8 +150,6 @@ int PackCom::buildLoader(const Filter *ft)
|
||||
assert(ft->calls > 0);
|
||||
addFilter16(ft->id);
|
||||
}
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +197,7 @@ void PackCom::pack(OutputFile *fo)
|
||||
ft.addvalue = getCallTrickOffset();
|
||||
// compress
|
||||
const unsigned overlap_range = ph.u_len < 0xFE00 - ft.addvalue ? 32 : 0;
|
||||
compressWithFilters(&ft, overlap_range);
|
||||
compressWithFilters(&ft, overlap_range, NULL_cconf);
|
||||
|
||||
const int lsize = getLoaderSize();
|
||||
MemBuffer loader(lsize);
|
||||
|
||||
+9
-7
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_COM_H
|
||||
#define __UPX_P_COM_H
|
||||
#define __UPX_P_COM_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -38,10 +38,12 @@ class PackCom : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
public:
|
||||
PackCom(InputFile *f) : super(f) { }
|
||||
PackCom(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_COM; }
|
||||
virtual const char *getName() const { return "dos/com"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.com" : "i286-dos16.com"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.com"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -56,7 +58,7 @@ protected:
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
|
||||
virtual void addFilter16(int filter_id);
|
||||
};
|
||||
|
||||
+29
-51
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -46,13 +46,14 @@ static const
|
||||
PackDjgpp2::PackDjgpp2(InputFile *f) :
|
||||
super(f), coff_offset(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40);
|
||||
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8);
|
||||
COMPILE_TIME_ASSERT(sizeof(stubify_stub) == 2048);
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(external_scnhdr_t, char)
|
||||
COMPILE_TIME_ASSERT_ALIGNOF(coff_header_t, char)
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_ADLER32 == 0xbf689ba8);
|
||||
COMPILE_TIME_ASSERT(STUBIFY_STUB_CRC32 == 0x2ae982b2);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(external_scnhdr_t) == 40)
|
||||
COMPILE_TIME_ASSERT(sizeof(coff_header_t) == 0xa8)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(external_scnhdr_t)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(coff_header_t)
|
||||
COMPILE_TIME_ASSERT(sizeof(stub_i386_dos32_djgpp2_stubify) == 2048)
|
||||
COMPILE_TIME_ASSERT(STUB_I386_DOS32_DJGPP2_STUBIFY_ADLER32 == 0xbf689ba8)
|
||||
COMPILE_TIME_ASSERT(STUB_I386_DOS32_DJGPP2_STUBIFY_CRC32 == 0x2ae982b2)
|
||||
//printf("0x%08x\n", upx_adler32(stubify_stub, sizeof(stubify_stub)));
|
||||
//assert(upx_adler32(stubify_stub, sizeof(stubify_stub)) == STUBIFY_STUB_ADLER32);
|
||||
}
|
||||
@@ -67,17 +68,19 @@ const int *PackDjgpp2::getCompressionMethods(int method, int level) const
|
||||
const int *PackDjgpp2::getFilters() const
|
||||
{
|
||||
static const int filters[] = {
|
||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x15, 0x12,
|
||||
-1 };
|
||||
0x26, 0x24, 0x49, 0x46, 0x16, 0x13, 0x14, 0x11,
|
||||
FT_ULTRA_BRUTE, 0x25, 0x15, 0x12,
|
||||
FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
|
||||
unsigned PackDjgpp2::findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range,
|
||||
unsigned upper_limit) const
|
||||
{
|
||||
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
|
||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||
o = (o + 0x3ff) &~ 0x1ff;
|
||||
return o;
|
||||
}
|
||||
@@ -89,16 +92,16 @@ Linker* PackDjgpp2::newLinker() const
|
||||
}
|
||||
|
||||
|
||||
int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
void PackDjgpp2::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
initLoader(stub_i386_dos32_djgpp2, sizeof(stub_i386_dos32_djgpp2));
|
||||
addLoader("IDENTSTR,DJ2MAIN1",
|
||||
ft->id ? "DJCALLT1" : "",
|
||||
"DJ2MAIN2",
|
||||
ph.method == M_LZMA ? "LZMA_INIT_STACK" : "",
|
||||
ph.first_offset_found == 1 ? "DJ2MAIN2" : "",
|
||||
M_IS_LZMA(ph.method) ? "LZMA_INIT_STACK" : "",
|
||||
getDecompressorSections(),
|
||||
ph.method == M_LZMA ? "LZMA_DONE_STACK" : "",
|
||||
M_IS_LZMA(ph.method) ? "LZMA_DONE_STACK" : "",
|
||||
"DJ2BSS00",
|
||||
NULL
|
||||
);
|
||||
@@ -109,8 +112,6 @@ int PackDjgpp2::buildLoader(const Filter *ft)
|
||||
addFilter32(ft->id);
|
||||
}
|
||||
addLoader("DJRETURN,+40C,UPX1HEAD", NULL);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -130,8 +131,8 @@ void PackDjgpp2::handleStub(OutputFile *fo)
|
||||
else
|
||||
{
|
||||
// "stubify" stub
|
||||
info("Adding stub: %ld bytes", (long)sizeof(stubify_stub));
|
||||
fo->write(stubify_stub, sizeof(stubify_stub));
|
||||
info("Adding stub: %ld bytes", (long)sizeof(stub_i386_dos32_djgpp2_stubify));
|
||||
fo->write(stub_i386_dos32_djgpp2_stubify, sizeof(stub_i386_dos32_djgpp2_stubify));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,29 +236,6 @@ void PackDjgpp2::stripDebug()
|
||||
}
|
||||
|
||||
|
||||
static bool defineFilterSymbols(Linker *linker, const Filter *ft)
|
||||
{
|
||||
if (ft->id == 0)
|
||||
return false;
|
||||
assert(ft->calls > 0);
|
||||
|
||||
linker->defineSymbol("filter_cto", ft->cto);
|
||||
linker->defineSymbol("filter_length",
|
||||
(ft->id & 0xf) % 3 == 0 ? ft->calls :
|
||||
ft->lastcall - ft->calls * 4);
|
||||
|
||||
#if 0
|
||||
if (0x80==(ft->id & 0xF0)) {
|
||||
int const mru = ph.n_mru ? 1+ ph.n_mru : 0;
|
||||
if (mru && mru!=256) {
|
||||
unsigned const is_pwr2 = (0==((mru -1) & mru));
|
||||
patch_le32(0x80 + (char *)loader, lsize - 0x80, "NMRU", mru - is_pwr2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
@@ -325,8 +303,8 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
// compress
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, 512, 0, NULL, &cconf);
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
// patch coff header #2
|
||||
const unsigned lsize = getLoaderSize();
|
||||
@@ -335,7 +313,7 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
data->size = ph.c_len; // new size of .data
|
||||
|
||||
unsigned stack = 1024 + ph.overlap_overhead + getDecompressorWrkmemSize();
|
||||
stack = ALIGN_UP(stack, 16);
|
||||
stack = ALIGN_UP(stack, 16u);
|
||||
if (bss->size < stack) // give it a .bss
|
||||
bss->size = stack;
|
||||
|
||||
@@ -351,7 +329,7 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
linker->defineSymbol("stack_for_lzma", bss->vaddr + bss->size);
|
||||
linker->defineSymbol("start_of_uncompressed", text->vaddr - hdrsize);
|
||||
linker->defineSymbol("start_of_compressed", data->vaddr);
|
||||
defineFilterSymbols(linker, &ft);
|
||||
defineFilterSymbols(&ft);
|
||||
|
||||
// we should not overwrite our decompressor during unpacking
|
||||
// the original coff header (which is put just before the
|
||||
@@ -369,7 +347,7 @@ void PackDjgpp2::pack(OutputFile *fo)
|
||||
data->size = ALIGN_UP(data->size, 4);
|
||||
|
||||
linker->defineSymbol("DJ2MAIN1", coff_hdr.a_entry);
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
|
||||
// prepare loader
|
||||
MemBuffer loader(lsize);
|
||||
|
||||
+12
-14
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_DJGPP2_H
|
||||
#define __UPX_P_DJGPP2_H
|
||||
#define __UPX_P_DJGPP2_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
virtual int getVersion() const { return 14; }
|
||||
virtual int getFormat() const { return UPX_F_DJGPP2_COFF; }
|
||||
virtual const char *getName() const { return "djgpp2/coff"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.djgpp2.coff"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -57,26 +58,24 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
|
||||
virtual unsigned findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
long coff_offset;
|
||||
|
||||
struct external_scnhdr_t
|
||||
{
|
||||
__packed_struct(external_scnhdr_t)
|
||||
char _[12]; // name, paddr
|
||||
LE32 vaddr;
|
||||
LE32 size;
|
||||
LE32 scnptr;
|
||||
char misc[12]; // relptr, lnnoptr, nreloc, nlnno
|
||||
char __[4]; // flags
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct coff_header_t
|
||||
{
|
||||
__packed_struct(coff_header_t)
|
||||
// ext_file_hdr
|
||||
LE16 f_magic;
|
||||
LE16 f_nscns;
|
||||
@@ -97,8 +96,7 @@ protected:
|
||||
|
||||
// section headers
|
||||
external_scnhdr_t sh[3];
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
coff_header_t coff_hdr;
|
||||
external_scnhdr_t *text,*data,*bss;
|
||||
|
||||
+303
-268
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,25 +21,43 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_ELF_H
|
||||
#define __UPX_P_ELF_H
|
||||
#define __UPX_P_ELF_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Some ELF type definitinons
|
||||
// N_Elf
|
||||
**************************************************************************/
|
||||
|
||||
namespace N_Elf {
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
template <class Word, class Addr, class Off, class Half>
|
||||
struct Ehdr
|
||||
// integral types
|
||||
template <class THalf, class TWord, class TXword, class TAddr, class TOff>
|
||||
struct ElfITypes
|
||||
{
|
||||
typedef THalf Half;
|
||||
typedef TWord Word;
|
||||
typedef TXword Xword;
|
||||
typedef TAddr Addr;
|
||||
typedef TOff Off;
|
||||
typedef THalf Section;
|
||||
typedef THalf Versym;
|
||||
};
|
||||
|
||||
|
||||
// The ELF file header. This appears at the start of every ELF file.
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Ehdr)
|
||||
typedef typename TElfITypes::Half Half;
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
|
||||
unsigned char e_ident[16]; /* Magic number and other info */
|
||||
Half e_type; /* Object file type */
|
||||
Half e_machine; /* Architecture */
|
||||
@@ -55,76 +73,72 @@ struct Ehdr
|
||||
Half e_shnum; /* Section header table entry count */
|
||||
Half e_shstrndx; /* Section header string table index */
|
||||
|
||||
enum { // e_ident[]
|
||||
EI_CLASS = 4,
|
||||
EI_DATA = 5, /* Data encoding */
|
||||
EI_VERSION = 6,
|
||||
EI_OSABI = 7,
|
||||
EI_ABIVERSION = 8,
|
||||
};
|
||||
enum { // e_ident[EI_CLASS]
|
||||
ELFCLASS32 = 1, /* 32-bit objects */
|
||||
ELFCLASS64 = 2, /* 64-bit objects */
|
||||
};
|
||||
enum { // e_ident[EI_DATA]
|
||||
ELFDATA2LSB = 1, /* 2's complement, little endian */
|
||||
ELFDATA2MSB = 2 /* 2's complement, big endian */
|
||||
};
|
||||
enum { // e_ident[EI_OSABI]
|
||||
ELFOSABI_NONE = 0,
|
||||
ELFOSABI_NETBSD = 2,
|
||||
ELFOSABI_LINUX = 3,
|
||||
ELFOSABI_FREEBSD = 9,
|
||||
ELFOSABI_OPENBSD = 12,
|
||||
ELFOSABI_ARM = 97
|
||||
};
|
||||
enum { // e_type
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4, /* Core file */
|
||||
};
|
||||
enum { // e_machine
|
||||
EM_386 = 3,
|
||||
EM_PPC = 20,
|
||||
EM_PPC64 = 21,
|
||||
EM_ARM = 40,
|
||||
EM_X86_64 = 62,
|
||||
};
|
||||
enum { // e_version
|
||||
EV_CURRENT = 1,
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
# define WANT_EHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class Word, class Addr>
|
||||
struct Dyn
|
||||
{
|
||||
Word d_tag;
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Dyn)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Xword d_tag;
|
||||
Addr d_val;
|
||||
|
||||
enum { // d_tag
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
# define WANT_DYN_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Rel)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Rela)
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
|
||||
Addr r_offset;
|
||||
Xword r_info;
|
||||
Xword r_addend;
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(External_Note)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
|
||||
Word xn_namesz; // includes terminating '\0'
|
||||
Word xn_datasz;
|
||||
Word xn_type;
|
||||
//char xn_name[N]; // terminate with '\0'
|
||||
//char xn_data[M]; // aligned to 0 mod 4
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// N_Elf32
|
||||
**************************************************************************/
|
||||
|
||||
namespace N_Elf32 {
|
||||
|
||||
// Program segment header.
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
|
||||
Word p_type; /* Segment type */
|
||||
Off p_offset; /* Segment file offset */
|
||||
Addr p_vaddr; /* Segment virtual address */
|
||||
@@ -134,25 +148,17 @@ struct Phdr
|
||||
Word p_flags; /* Segment flags */
|
||||
Word p_align; /* Segment alignment */
|
||||
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_NOTE = 4, /* Auxiliary information (esp. OpenBSD) */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
template <class Word, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Word sh_flags; /* Section flags */
|
||||
@@ -164,94 +170,50 @@ struct Shdr
|
||||
Word sh_addralign; /* Section alignment */
|
||||
Word sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
enum { // sh_flags
|
||||
SHF_WRITE = (1 << 0), /* Writable */
|
||||
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
|
||||
SHF_EXECINSTR = (1 << 2), /* Executable */
|
||||
SHF_MERGE = (1 << 4), /* Might be merged */
|
||||
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
|
||||
SHF_INFO_LINK = (1 << 6), /* `sh_info' contains SHT index */
|
||||
SHF_LINK_ORDER = (1 << 7), /* Preserve order after combining */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
template <class TT16, class TT32>
|
||||
struct Sym
|
||||
{
|
||||
TT32 st_name; /* symbol name (index into string table) */
|
||||
TT32 st_value; /* symbol value */
|
||||
TT32 st_size; /* symbol size */
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Section Section;
|
||||
|
||||
Word st_name; /* symbol name (index into string table) */
|
||||
Addr st_value; /* symbol value */
|
||||
Word st_size; /* symbol size */
|
||||
unsigned char st_info; /* symbol type and binding */
|
||||
unsigned char st_other; /* symbol visibility */
|
||||
TT16 st_shndx; /* section index */
|
||||
Section st_shndx; /* section index */
|
||||
|
||||
unsigned int st_bind(unsigned int x) const { return 0xf & (x>>4); }
|
||||
unsigned int st_type(unsigned int x) const { return 0xf & x ; }
|
||||
unsigned char St_info(unsigned bind, unsigned type) const { return (bind<<4) + (0xf & type); }
|
||||
# define WANT_SYM_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
|
||||
enum { // st_bind (high 4 bits of st_info)
|
||||
STB_LOCAL = 0, /* Local symbol */
|
||||
STB_GLOBAL = 1, /* Global symbol */
|
||||
STB_WEAK = 2, /* Weak symbol */
|
||||
};
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
enum { // st_type (low 4 bits of st_info)
|
||||
STT_NOTYPE = 0, /* Symbol type is unspecified */
|
||||
STT_OBJECT = 1, /* Symbol is a data object */
|
||||
STT_FUNC = 2, /* Symbol is a code object */
|
||||
STT_SECTION = 3, /* Symbol associated with a section */
|
||||
STT_FILE = 4, /* Symbol's name is file name */
|
||||
STT_COMMON = 5, /* Symbol is a common data object */
|
||||
STT_TLS = 6, /* Symbol is thread-local data object*/
|
||||
};
|
||||
|
||||
enum { // st_other (visibility)
|
||||
STV_DEFAULT = 0, /* Default symbol visibility rules */
|
||||
STV_INTERNAL = 1, /* Processor specific hidden class */
|
||||
STV_HIDDEN = 2, /* Sym unavailable in other modules */
|
||||
STV_PROTECTED= 3, /* Not preemptible, not exported */
|
||||
};
|
||||
|
||||
enum { // st_shndx
|
||||
SHN_UNDEF = 0, /* Undefined section */
|
||||
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
|
||||
SHN_COMMON = 0xfff2, /* Associated symbol is common */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
} // namespace N_Elf32
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// N_Elf64
|
||||
**************************************************************************/
|
||||
|
||||
namespace N_Elf64 {
|
||||
|
||||
// Program segment header.
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Phdr
|
||||
{
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Phdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
|
||||
Word p_type; /* Segment type */
|
||||
Word p_flags; /* Segment flags */
|
||||
Off p_offset; /* Segment file offset */
|
||||
@@ -261,24 +223,18 @@ struct Phdr
|
||||
Xword p_memsz; /* Segment size in memory */
|
||||
Xword p_align; /* Segment alignment */
|
||||
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_PHDR = 6, /* Entry for header table itself */
|
||||
};
|
||||
# define WANT_PHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4, /* Segment is readable */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
template <class Word, class Xword, class Addr, class Off>
|
||||
struct Shdr
|
||||
{
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Shdr)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Off Off;
|
||||
|
||||
Word sh_name; /* Section name (string tbl index) */
|
||||
Word sh_type; /* Section type */
|
||||
Xword sh_flags; /* Section flags */
|
||||
@@ -290,115 +246,194 @@ struct Shdr
|
||||
Xword sh_addralign; /* Section alignment */
|
||||
Xword sh_entsize; /* Entry size if section holds table */
|
||||
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7, /* Prelink library list */
|
||||
};
|
||||
}
|
||||
__attribute_packed;
|
||||
# define WANT_SHDR_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
template <class TElfITypes>
|
||||
__packed_struct(Sym)
|
||||
typedef typename TElfITypes::Word Word;
|
||||
typedef typename TElfITypes::Xword Xword;
|
||||
typedef typename TElfITypes::Addr Addr;
|
||||
typedef typename TElfITypes::Section Section;
|
||||
|
||||
Word st_name; /* symbol name (index into string table) */
|
||||
unsigned char st_info; /* symbol type and binding */
|
||||
unsigned char st_other; /* symbol visibility */
|
||||
Section st_shndx; /* section index */
|
||||
Addr st_value; /* symbol value */
|
||||
Xword st_size; /* symbol size */
|
||||
|
||||
# define WANT_SYM_ENUM 1
|
||||
# include "p_elf_enum.h"
|
||||
|
||||
static unsigned int get_st_bind(unsigned x) { return 0xf & (x>>4); }
|
||||
static unsigned int get_st_type(unsigned x) { return 0xf & x ; }
|
||||
static unsigned char make_st_info(unsigned bind, unsigned type)
|
||||
{ return (unsigned char) (((bind<<4) + (0xf & type)) & 0xff); }
|
||||
__packed_struct_end()
|
||||
|
||||
|
||||
} // namespace N_Elf64
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// now for the actual types
|
||||
// aggregate types into an ElfClass
|
||||
**************************************************************************/
|
||||
|
||||
#define P N_BELE_CTP::HostPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf32_Ehdr;
|
||||
typedef N_Elf32::Phdr<P::U32,P::U32,P::U32> Elf32_Phdr;
|
||||
typedef N_Elf32::Shdr<P::U32,P::U32,P::U32> Elf32_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U32,P::U32> Elf32_Dyn;
|
||||
typedef N_Elf32::Sym <P::U16,P::U32> Elf32_Sym;
|
||||
#undef P
|
||||
namespace N_Elf {
|
||||
|
||||
#define P N_BELE_CTP::BEPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf_BE32_Ehdr;
|
||||
typedef N_Elf32::Phdr<P::U32,P::U32,P::U32> Elf_BE32_Phdr;
|
||||
typedef N_Elf32::Shdr<P::U32,P::U32,P::U32> Elf_BE32_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U32,P::U32> Elf_BE32_Dyn;
|
||||
typedef N_Elf32::Sym <P::U16,P::U32> Elf_BE32_Sym;
|
||||
#undef P
|
||||
template <class TP>
|
||||
struct ElfClass_32
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
#define P N_BELE_CTP::LEPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf_LE32_Ehdr;
|
||||
typedef N_Elf32::Phdr<P::U32,P::U32,P::U32> Elf_LE32_Phdr;
|
||||
typedef N_Elf32::Shdr<P::U32,P::U32,P::U32> Elf_LE32_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U32,P::U32> Elf_LE32_Dyn;
|
||||
typedef N_Elf32::Sym <P::U16,P::U32> Elf_LE32_Sym;
|
||||
#undef P
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Elf::ElfITypes<TE16, TE32, TE32, TE32, TE32> ElfITypes;
|
||||
|
||||
#define P N_BELE_CTP::HostPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf64_Ehdr;
|
||||
typedef N_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf64_Phdr;
|
||||
typedef N_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf64_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U64,P::U64> Elf64_Dyn;
|
||||
#undef P
|
||||
// ELF types
|
||||
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
|
||||
typedef N_Elf32::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf32::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf32::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
#define P N_BELE_CTP::BEPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf_BE64_Ehdr;
|
||||
typedef N_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf_BE64_Phdr;
|
||||
typedef N_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf_BE64_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U64,P::U64> Elf_BE64_Dyn;
|
||||
#undef P
|
||||
|
||||
#define P N_BELE_CTP::LEPolicy
|
||||
typedef N_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf_LE64_Ehdr;
|
||||
typedef N_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf_LE64_Phdr;
|
||||
typedef N_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf_LE64_Shdr;
|
||||
typedef N_Elf ::Dyn <P::U64,P::U64> Elf_LE64_Dyn;
|
||||
#undef P
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(Ehdr) == 52)
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 32)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 40)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 8)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 16)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
|
||||
template <class TP>
|
||||
struct ElfClass_64
|
||||
{
|
||||
typedef TP BeLePolicy;
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Sym) == 16)
|
||||
// integral types (target endianness)
|
||||
typedef typename TP::U16 TE16;
|
||||
typedef typename TP::U32 TE32;
|
||||
typedef typename TP::U64 TE64;
|
||||
typedef N_Elf::ElfITypes<TE16, TE32, TE64, TE64, TE64> ElfITypes;
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
|
||||
// ELF types
|
||||
typedef N_Elf ::Ehdr<ElfITypes> Ehdr;
|
||||
typedef N_Elf64::Phdr<ElfITypes> Phdr;
|
||||
typedef N_Elf64::Shdr<ElfITypes> Shdr;
|
||||
typedef N_Elf ::Dyn <ElfITypes> Dyn;
|
||||
typedef N_Elf ::Rel <ElfITypes> Rel;
|
||||
typedef N_Elf ::Rela<ElfITypes> Rela;
|
||||
typedef N_Elf64::Sym <ElfITypes> Sym;
|
||||
typedef N_Elf ::External_Note<ElfITypes> External_Note;
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
|
||||
static void compileTimeAssertions() {
|
||||
BeLePolicy::compileTimeAssertions();
|
||||
COMPILE_TIME_ASSERT(sizeof(Ehdr) == 64)
|
||||
COMPILE_TIME_ASSERT(sizeof(Phdr) == 56)
|
||||
COMPILE_TIME_ASSERT(sizeof(Shdr) == 64)
|
||||
COMPILE_TIME_ASSERT(sizeof(Dyn) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rel) == 16)
|
||||
COMPILE_TIME_ASSERT(sizeof(Rela) == 24)
|
||||
COMPILE_TIME_ASSERT(sizeof(Sym) == 24)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Ehdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Phdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Shdr)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Dyn)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rel)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Rela)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(Sym)
|
||||
}
|
||||
};
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Dyn) == 16)
|
||||
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Ehdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Phdr) == 56)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Shdr) == 64)
|
||||
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Dyn) == 16)
|
||||
} // namespace N_Elf
|
||||
|
||||
|
||||
typedef N_Elf::ElfClass_32<N_BELE_CTP::HostPolicy> ElfClass_Host32;
|
||||
typedef N_Elf::ElfClass_64<N_BELE_CTP::HostPolicy> ElfClass_Host64;
|
||||
typedef N_Elf::ElfClass_32<N_BELE_CTP::BEPolicy> ElfClass_BE32;
|
||||
typedef N_Elf::ElfClass_64<N_BELE_CTP::BEPolicy> ElfClass_BE64;
|
||||
typedef N_Elf::ElfClass_32<N_BELE_CTP::LEPolicy> ElfClass_LE32;
|
||||
typedef N_Elf::ElfClass_64<N_BELE_CTP::LEPolicy> ElfClass_LE64;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// shortcuts
|
||||
**************************************************************************/
|
||||
|
||||
typedef ElfClass_Host32::Ehdr Elf32_Ehdr;
|
||||
typedef ElfClass_Host32::Phdr Elf32_Phdr;
|
||||
typedef ElfClass_Host32::Shdr Elf32_Shdr;
|
||||
typedef ElfClass_Host32::Dyn Elf32_Dyn;
|
||||
typedef ElfClass_Host32::Rel Elf32_Rel;
|
||||
typedef ElfClass_Host32::Rela Elf32_Rela;
|
||||
typedef ElfClass_Host32::Sym Elf32_Sym;
|
||||
typedef ElfClass_Host32::External_Note Elf32_External_Note;
|
||||
|
||||
typedef ElfClass_Host64::Ehdr Elf64_Ehdr;
|
||||
typedef ElfClass_Host64::Phdr Elf64_Phdr;
|
||||
typedef ElfClass_Host64::Shdr Elf64_Shdr;
|
||||
typedef ElfClass_Host64::Dyn Elf64_Dyn;
|
||||
typedef ElfClass_Host64::Rel Elf64_Rel;
|
||||
typedef ElfClass_Host64::Rela Elf64_Rela;
|
||||
typedef ElfClass_Host64::Sym Elf64_Sym;
|
||||
typedef ElfClass_Host64::External_Note Elf64_External_Note;
|
||||
|
||||
typedef ElfClass_BE32::Ehdr Elf_BE32_Ehdr;
|
||||
typedef ElfClass_BE32::Phdr Elf_BE32_Phdr;
|
||||
typedef ElfClass_BE32::Shdr Elf_BE32_Shdr;
|
||||
typedef ElfClass_BE32::Dyn Elf_BE32_Dyn;
|
||||
typedef ElfClass_BE32::Rel Elf_BE32_Rel;
|
||||
typedef ElfClass_BE32::Rela Elf_BE32_Rela;
|
||||
typedef ElfClass_BE32::Sym Elf_BE32_Sym;
|
||||
typedef ElfClass_BE32::External_Note Elf_BE32_External_Note;
|
||||
|
||||
typedef ElfClass_BE64::Ehdr Elf_BE64_Ehdr;
|
||||
typedef ElfClass_BE64::Phdr Elf_BE64_Phdr;
|
||||
typedef ElfClass_BE64::Shdr Elf_BE64_Shdr;
|
||||
typedef ElfClass_BE64::Dyn Elf_BE64_Dyn;
|
||||
typedef ElfClass_BE64::Rel Elf_BE64_Rel;
|
||||
typedef ElfClass_BE64::Rela Elf_BE64_Rela;
|
||||
typedef ElfClass_BE64::Sym Elf_BE64_Sym;
|
||||
typedef ElfClass_BE64::External_Note Elf_BE64_External_Note;
|
||||
|
||||
typedef ElfClass_LE32::Ehdr Elf_LE32_Ehdr;
|
||||
typedef ElfClass_LE32::Phdr Elf_LE32_Phdr;
|
||||
typedef ElfClass_LE32::Shdr Elf_LE32_Shdr;
|
||||
typedef ElfClass_LE32::Dyn Elf_LE32_Dyn;
|
||||
typedef ElfClass_LE32::Rel Elf_LE32_Rel;
|
||||
typedef ElfClass_LE32::Rela Elf_LE32_Rela;
|
||||
typedef ElfClass_LE32::Sym Elf_LE32_Sym;
|
||||
typedef ElfClass_LE32::External_Note Elf_LE32_External_Note;
|
||||
|
||||
typedef ElfClass_LE64::Ehdr Elf_LE64_Ehdr;
|
||||
typedef ElfClass_LE64::Phdr Elf_LE64_Phdr;
|
||||
typedef ElfClass_LE64::Shdr Elf_LE64_Shdr;
|
||||
typedef ElfClass_LE64::Dyn Elf_LE64_Dyn;
|
||||
typedef ElfClass_LE64::Rel Elf_LE64_Rel;
|
||||
typedef ElfClass_LE64::Rela Elf_LE64_Rela;
|
||||
typedef ElfClass_LE64::Sym Elf_LE64_Sym;
|
||||
typedef ElfClass_LE64::External_Note Elf_LE64_External_Note;
|
||||
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
/* p_elf_enum.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Use the preprocessor to work around
|
||||
// - that the types embedding these enums have to be PODs, and
|
||||
// deriving from an empty base class (which is the usual C++ way
|
||||
// of "importing" enums) does not yield a POD any more
|
||||
// - that older compilers do not correctly perform EBCO
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef WANT_EHDR_ENUM
|
||||
#undef WANT_EHDR_ENUM
|
||||
enum { // e_ident[]
|
||||
EI_CLASS = 4,
|
||||
EI_DATA = 5, /* Data encoding */
|
||||
EI_VERSION = 6,
|
||||
EI_OSABI = 7,
|
||||
EI_ABIVERSION = 8
|
||||
};
|
||||
enum { // e_ident[EI_CLASS]
|
||||
ELFCLASS32 = 1, /* 32-bit objects */
|
||||
ELFCLASS64 = 2 /* 64-bit objects */
|
||||
};
|
||||
enum { // e_ident[EI_DATA]
|
||||
ELFDATA2LSB = 1, /* 2's complement, little endian */
|
||||
ELFDATA2MSB = 2 /* 2's complement, big endian */
|
||||
};
|
||||
enum { // e_ident[EI_OSABI]
|
||||
ELFOSABI_NONE = 0, // == ELFOSABI_SYSV
|
||||
ELFOSABI_NETBSD = 2,
|
||||
ELFOSABI_LINUX = 3,
|
||||
ELFOSABI_FREEBSD = 9,
|
||||
ELFOSABI_OPENBSD = 12,
|
||||
ELFOSABI_ARM = 97
|
||||
};
|
||||
enum { // e_type
|
||||
ET_NONE = 0, /* No file type */
|
||||
ET_REL = 1, /* Relocatable file */
|
||||
ET_EXEC = 2, /* Executable file */
|
||||
ET_DYN = 3, /* Shared object file */
|
||||
ET_CORE = 4 /* Core file */
|
||||
};
|
||||
enum { // e_machine
|
||||
EM_386 = 3,
|
||||
EM_MIPS = 8,
|
||||
EM_MIPS_RS3_LE = 10, /* MIPS R3000 little-endian */
|
||||
EM_PPC = 20,
|
||||
EM_PPC64 = 21,
|
||||
EM_ARM = 40,
|
||||
EM_X86_64 = 62
|
||||
|
||||
};
|
||||
enum { // e_version
|
||||
EV_CURRENT = 1
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_PHDR_ENUM
|
||||
#undef WANT_PHDR_ENUM
|
||||
enum { // p_type
|
||||
PT_LOAD = 1, /* Loadable program segment */
|
||||
PT_DYNAMIC = 2, /* Dynamic linking information */
|
||||
PT_INTERP = 3, /* Name of program interpreter */
|
||||
PT_NOTE = 4, /* Auxiliary information (esp. OpenBSD) */
|
||||
PT_PHDR = 6 /* Entry for header table itself */
|
||||
};
|
||||
|
||||
enum { // p_flags
|
||||
PF_X = 1, /* Segment is executable */
|
||||
PF_W = 2, /* Segment is writable */
|
||||
PF_R = 4 /* Segment is readable */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_SHDR_ENUM
|
||||
#undef WANT_SHDR_ENUM
|
||||
enum { // sh_type
|
||||
SHT_NULL = 0, /* Section header table entry unused */
|
||||
SHT_PROGBITS = 1, /* Program data */
|
||||
SHT_SYMTAB = 2, /* Symbol table */
|
||||
SHT_STRTAB = 3, /* String table */
|
||||
SHT_RELA = 4, /* Relocation entries with addends */
|
||||
SHT_HASH = 5, /* Symbol hash table */
|
||||
SHT_DYNAMIC = 6, /* Dynamic linking information */
|
||||
SHT_NOTE = 7, /* Notes */
|
||||
SHT_NOBITS = 8, /* Program space with no data (bss) */
|
||||
SHT_REL = 9, /* Relocation entries, no addends */
|
||||
SHT_SHLIB = 10, /* Reserved */
|
||||
SHT_DYNSYM = 11, /* Dynamic linker symbol table */
|
||||
/* 12, 13 hole */
|
||||
SHT_INIT_ARRAY = 14, /* Array of constructors */
|
||||
SHT_FINI_ARRAY = 15, /* Array of destructors */
|
||||
SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */
|
||||
SHT_GROUP = 17, /* Section group */
|
||||
SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */
|
||||
SHT_GNU_LIBLIST = 0x6ffffff7 /* Prelink library list */
|
||||
};
|
||||
|
||||
enum { // sh_flags
|
||||
SHF_WRITE = (1 << 0), /* Writable */
|
||||
SHF_ALLOC = (1 << 1), /* Occupies memory during execution */
|
||||
SHF_EXECINSTR = (1 << 2), /* Executable */
|
||||
SHF_MERGE = (1 << 4), /* Might be merged */
|
||||
SHF_STRINGS = (1 << 5), /* Contains nul-terminated strings */
|
||||
SHF_INFO_LINK = (1 << 6), /* 'sh_info' contains SHT index */
|
||||
SHF_LINK_ORDER = (1 << 7) /* Preserve order after combining */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_DYN_ENUM
|
||||
#undef WANT_DYN_ENUM
|
||||
enum { // d_tag
|
||||
DT_NULL = 0, /* End flag */
|
||||
DT_NEEDED = 1, /* Name of needed library */
|
||||
DT_PLTRELSZ = 2, /* Size in bytes of PLT relocs */
|
||||
DT_HASH = 4, /* Hash table of symbol names */
|
||||
DT_STRTAB = 5, /* String table */
|
||||
DT_SYMTAB = 6, /* Symbol table */
|
||||
DT_RELA = 7, /* Relocations which do contain an addend */
|
||||
DT_RELAENT = 9, /* Size of one RELA relocation */
|
||||
DT_INIT = 12, /* Address of init function */
|
||||
DT_REL = 17, /* Relocations which contain no addend */
|
||||
DT_RELENT = 19, /* Size of one Rel relocation */
|
||||
DT_STRSZ = 10, /* Sizeof string table */
|
||||
DT_PLTREL = 20, /* Type of reloc in PLT */
|
||||
DT_TEXTREL = 22, /* Reloc might modify .text */
|
||||
DT_JMPREL = 23, /* Address of PLT relocs */
|
||||
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
|
||||
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
|
||||
DT_VERSYM = 0x6ffffff0, /* version[] for each symbol */
|
||||
DT_VERDEF = 0x6ffffffc, /* version definitions[] */
|
||||
DT_VERNEEDED= 0x6ffffffe /* version[] needed */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_SYM_ENUM
|
||||
#undef WANT_SYM_ENUM
|
||||
enum { // st_bind (high 4 bits of st_info)
|
||||
STB_LOCAL = 0, /* Local symbol */
|
||||
STB_GLOBAL = 1, /* Global symbol */
|
||||
STB_WEAK = 2 /* Weak symbol */
|
||||
};
|
||||
|
||||
enum { // st_type (low 4 bits of st_info)
|
||||
STT_NOTYPE = 0, /* Symbol type is unspecified */
|
||||
STT_OBJECT = 1, /* Symbol is a data object */
|
||||
STT_FUNC = 2, /* Symbol is a code object */
|
||||
STT_SECTION = 3, /* Symbol associated with a section */
|
||||
STT_FILE = 4, /* Symbol's name is file name */
|
||||
STT_COMMON = 5, /* Symbol is a common data object */
|
||||
STT_TLS = 6 /* Symbol is thread-local data object*/
|
||||
};
|
||||
|
||||
enum { // st_other (visibility)
|
||||
STV_DEFAULT = 0, /* Default symbol visibility rules */
|
||||
STV_INTERNAL = 1, /* Processor specific hidden class */
|
||||
STV_HIDDEN = 2, /* Sym unavailable in other modules */
|
||||
STV_PROTECTED= 3 /* Not preemptible, not exported */
|
||||
};
|
||||
|
||||
enum { // st_shndx
|
||||
SHN_UNDEF = 0, /* Undefined section */
|
||||
SHN_ABS = 0xfff1, /* Associated symbol is absolute */
|
||||
SHN_COMMON = 0xfff2 /* Associated symbol is common */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WANT_NHDR_ENUM
|
||||
#undef WANT_NHDR_ENUM
|
||||
enum { // ELF PT_NOTE types
|
||||
#define ELF_NOTE_GNU_NAME "GNU\0"
|
||||
NT_GNU_ABI_TAG = 1,
|
||||
NT_GNU_HWCAP = 2,
|
||||
NT_GNU_BUILD_ID = 3,
|
||||
|
||||
#define ELF_NOTE_OPENBSD_NAME "OpenBSD\0"
|
||||
NHDR_OPENBSD_TAG = 1,
|
||||
|
||||
#define ELF_NOTE_NETBSD_NAME "NetBSD\0"
|
||||
NHDR_NETBSD_TAG = 1,
|
||||
NHDR_CHECKSUM_TAG = 2,
|
||||
NHDR_PAX_TAG = 3
|
||||
};
|
||||
|
||||
enum { // descsz descriptor sizes
|
||||
GNU_ABI_DESCSZ = 16, // int GNU_OS, major, minor, subminor;
|
||||
NETBSD_DESCSZ = 4, // major_ver * (10**8) + minor
|
||||
OPENBSD_DESCSZ = 4, // 32-bit zero
|
||||
// CHECKSUM_DESCSZ is 2*sizeof(short) + sizeof(checksum)
|
||||
PAX_DESCSZ = 4 // 32-bit mask
|
||||
};
|
||||
|
||||
enum { // GNU OS/version
|
||||
GNU_OS_LINUX = 0,
|
||||
GNU_OS_HURD = 1,
|
||||
GNU_OS_SOLARIS = 2
|
||||
};
|
||||
|
||||
enum { // NetBSD checksum methods
|
||||
CHECKSUM_CRC32 = 1,
|
||||
CHECKSUM_MD5 = 2,
|
||||
CHECKSUM_SHA1 = 3,
|
||||
CHECKSUM_SHA256 = 4
|
||||
};
|
||||
|
||||
#define ELF_NOTE_PAX_NAME "PaX\0"
|
||||
enum { // NetBSD PaX bit values
|
||||
PAX_MPROTECT = (1<<0), /* force enable Mprotect */
|
||||
PAX_NOMPROTECT = (1<<1), /* force disable Mprotect */
|
||||
PAX_GUARD = (1<<2), /* force enable SEGVguard */
|
||||
PAX_NOGUARD = (1<<3), /* force disable SEGVguard */
|
||||
PAX_ASLR = (1<<4), /* force enable ASLR */
|
||||
PAX_NOASLR = (1<<5) /* force disable ASLR */
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+10
-12
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -94,14 +94,12 @@ void PackElks8086::readKernel()
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int PackElks8086::buildLoader(const Filter *ft)
|
||||
void PackElks8086::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
// FIXME
|
||||
UNUSED(ft);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +112,7 @@ void PackElks8086::pack(OutputFile *fo)
|
||||
ft.buf_len = ph.u_len;
|
||||
ft.addvalue = kernel_entry;
|
||||
// compress
|
||||
compressWithFilters(&ft, overlap_range);
|
||||
compressWithFilters(&ft, overlap_range, NULL_cconf);
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
MemBuffer loader(lsize);
|
||||
@@ -123,11 +121,11 @@ void PackElks8086::pack(OutputFile *fo)
|
||||
patchPackHeader(loader, lsize);
|
||||
#if 0
|
||||
// FIXME
|
||||
defineFilterSymbols();
|
||||
defineFilterSymbols(&ft);
|
||||
defineDecompressorSymbols();
|
||||
patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
|
||||
patch_le32(loader, lsize, "KEIP", kernel_entry);
|
||||
patch_le32(loader, lsize, "STAK", stack_during_uncompression);
|
||||
//patch_le32(loader, lsize, "ESI1", zimage_offset + lsize);
|
||||
//patch_le32(loader, lsize, "KEIP", kernel_entry);
|
||||
//patch_le32(loader, lsize, "STAK", stack_during_uncompression);
|
||||
#endif
|
||||
|
||||
boot_sect_t * const bs = (boot_sect_t *) ((unsigned char *) setup_buf);
|
||||
|
||||
+218
-61
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -50,14 +50,22 @@ static const
|
||||
PackExe::PackExe(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(exe_header_t) == 32)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(exe_header_t)
|
||||
ih_exesize = ih_imagesize = ih_overlay = 0;
|
||||
stack_for_lzma = 0;
|
||||
use_clear_dirty_stack = false;
|
||||
}
|
||||
|
||||
|
||||
const int *PackExe::getCompressionMethods(int method, int level) const
|
||||
{
|
||||
bool small = ih_imagesize <= 256*1024;
|
||||
// disable lzma for "--brute" unless explicitly given "--lzma"
|
||||
// WARNING: this side effect persists for later files!
|
||||
if (opt->all_methods_use_lzma && !opt->method_lzma_seen)
|
||||
opt->all_methods_use_lzma = false;
|
||||
return Packer::getDefaultCompressionMethods_8(method, level, small);
|
||||
}
|
||||
|
||||
@@ -73,7 +81,7 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
#define oh (*eh)
|
||||
// fill new exe header
|
||||
int flag = 0;
|
||||
if (!opt->dos_exe.no_reloc)
|
||||
if (!opt->dos_exe.no_reloc && !M_IS_LZMA(ph.method))
|
||||
flag |= USEJUMP;
|
||||
if (ih.relocs == 0)
|
||||
flag |= NORELOC;
|
||||
@@ -82,7 +90,16 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
oh.ident = 'M' + 'Z' * 256;
|
||||
oh.headsize16 = 2;
|
||||
|
||||
oh.sp = ih.sp > 0x200 ? (unsigned) ih.sp : 0x200;
|
||||
unsigned minsp = 0x200;
|
||||
if (M_IS_LZMA(ph.method))
|
||||
minsp = stack_for_lzma;
|
||||
minsp = ALIGN_UP(minsp, 16u);
|
||||
assert(minsp < 0xff00);
|
||||
if (oh.sp > minsp)
|
||||
minsp = oh.sp;
|
||||
if (minsp < 0xff00 - 2)
|
||||
minsp = ALIGN_UP(minsp, 2u);
|
||||
oh.sp = minsp;
|
||||
|
||||
unsigned destpara = (ph.u_len + ph.overlap_overhead - ph.c_len + 31) / 16;
|
||||
oh.ss = ph.c_len/16 + destpara;
|
||||
@@ -94,27 +111,118 @@ int PackExe::fillExeHeader(struct exe_header_t *eh) const
|
||||
|
||||
if (oh.ss != ih.ss)
|
||||
flag |= SS;
|
||||
if (oh.sp != ih.sp)
|
||||
if (oh.sp != ih.sp || M_IS_LZMA(ph.method))
|
||||
flag |= SP;
|
||||
return flag;
|
||||
#undef oh
|
||||
}
|
||||
|
||||
|
||||
int PackExe::buildLoader(const Filter *)
|
||||
void PackExe::addLoaderEpilogue(int flag)
|
||||
{
|
||||
struct exe_header_t tmp_oh;
|
||||
int flag = fillExeHeader(&tmp_oh);
|
||||
addLoader("EXEMAIN5", NULL);
|
||||
if (relocsize)
|
||||
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
|
||||
"EXERELO1",
|
||||
has_9a ? "EXEREL9A" : "",
|
||||
"EXERELO2",
|
||||
ih_exesize > 0xFE00 ? "EXEREBIG" : "",
|
||||
"EXERELO3",
|
||||
NULL
|
||||
);
|
||||
addLoader("EXEMAIN8",
|
||||
device_driver ? "DEVICEEND" : "",
|
||||
(flag & SS) ? "EXESTACK" : "",
|
||||
(flag & SP) ? "EXESTASP" : "",
|
||||
(flag & USEJUMP) ? "EXEJUMPF" : "",
|
||||
NULL
|
||||
);
|
||||
if (!(flag & USEJUMP))
|
||||
addLoader(ih.cs ? "EXERCSPO" : "",
|
||||
"EXERETIP",
|
||||
NULL
|
||||
);
|
||||
|
||||
linker->defineSymbol("original_cs", ih.cs);
|
||||
linker->defineSymbol("original_ip", ih.ip);
|
||||
linker->defineSymbol("original_sp", ih.sp);
|
||||
linker->defineSymbol("original_ss", ih.ss);
|
||||
linker->defineSymbol("reloc_size",
|
||||
(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff)
|
||||
>= relocsize ? 0 : MAXRELOCS) - relocsize);
|
||||
}
|
||||
|
||||
void PackExe::buildLoader(const Filter *)
|
||||
{
|
||||
// get flag
|
||||
exe_header_t dummy_oh;
|
||||
int flag = fillExeHeader(&dummy_oh);
|
||||
|
||||
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
|
||||
|
||||
if (M_IS_LZMA(ph.method))
|
||||
{
|
||||
addLoader("LZMA_DEC00",
|
||||
opt->small ? "LZMA_DEC10" : "LZMA_DEC20",
|
||||
"LZMA_DEC30",
|
||||
use_clear_dirty_stack ? "LZMA_DEC31" : "",
|
||||
"LZMA_DEC32",
|
||||
ph.u_len > 0xffff ? "LZMA_DEC33" : "",
|
||||
NULL
|
||||
);
|
||||
|
||||
addLoaderEpilogue(flag);
|
||||
defineDecompressorSymbols();
|
||||
const unsigned lsize0 = getLoaderSize();
|
||||
|
||||
// Lzma decompression code starts at ss:0x10, and its size is
|
||||
// lsize bytes. It also needs getDecompressorWrkmemSize() bytes
|
||||
// during uncompression. It also uses some stack, so 0x100
|
||||
// more bytes are allocated
|
||||
stack_for_lzma = 0x10 + lsize0 + getDecompressorWrkmemSize() + 0x100;
|
||||
stack_for_lzma = ALIGN_UP(stack_for_lzma, 16u);
|
||||
|
||||
unsigned clear_dirty_stack_low = 0x10 + lsize0;
|
||||
clear_dirty_stack_low = ALIGN_UP(clear_dirty_stack_low, 2u);
|
||||
if (use_clear_dirty_stack)
|
||||
linker->defineSymbol("clear_dirty_stack_low", clear_dirty_stack_low);
|
||||
|
||||
relocateLoader();
|
||||
const unsigned lsize = getLoaderSize();
|
||||
assert(lsize0 == lsize);
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
|
||||
MemBuffer compressed_lzma;
|
||||
compressed_lzma.allocForCompression(lsize);
|
||||
unsigned c_len_lzma = MemBuffer::getSizeForCompression(lsize);
|
||||
int r = upx_compress(loader, lsize, compressed_lzma, &c_len_lzma,
|
||||
NULL, M_NRV2B_LE16, 9, NULL, NULL);
|
||||
assert(r == UPX_E_OK); assert(c_len_lzma < lsize);
|
||||
|
||||
info("lzma+relocator code compressed: %u -> %u", lsize, c_len_lzma);
|
||||
// reinit the loader
|
||||
initLoader(stub_i086_dos16_exe, sizeof(stub_i086_dos16_exe));
|
||||
// prepare loader
|
||||
if (device_driver)
|
||||
addLoader("DEVICEENTRY,LZMADEVICE,DEVICEENTRY2", NULL);
|
||||
|
||||
linker->addSection("COMPRESSED_LZMA", compressed_lzma, c_len_lzma, 0);
|
||||
addLoader("LZMAENTRY,NRV2B160,NRVDDONE,NRVDECO1,NRVGTD00,NRVDECO2",
|
||||
NULL);
|
||||
|
||||
}
|
||||
else if (device_driver)
|
||||
addLoader("DEVICEENTRY,DEVICEENTRY2", NULL);
|
||||
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
if (device_driver)
|
||||
addLoader("DEVICEENTRY", NULL);
|
||||
addLoader("EXEENTRY",
|
||||
device_driver ? "DEVICESUB" : "EXESUB",
|
||||
M_IS_LZMA(ph.method) && device_driver ? "LONGSUB" : "SHORTSUB",
|
||||
"JNCDOCOPY",
|
||||
relocsize ? "EXERELPU" : "",
|
||||
"EXEMAIN4,+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
"EXEMAIN4",
|
||||
M_IS_LZMA(ph.method) ? "" : "EXEMAIN4B",
|
||||
"EXEMAIN4C",
|
||||
M_IS_LZMA(ph.method) ? "COMPRESSED_LZMA_START,COMPRESSED_LZMA" : "",
|
||||
"+G5DXXXX,UPX1HEAD,EXECUTPO",
|
||||
NULL
|
||||
);
|
||||
if (ph.method == M_NRV2B_8)
|
||||
@@ -153,32 +261,12 @@ int PackExe::buildLoader(const Filter *)
|
||||
"NRV2EEX9",
|
||||
NULL
|
||||
);
|
||||
else if M_IS_LZMA(ph.method)
|
||||
return;
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
addLoader("EXEMAIN5", NULL);
|
||||
if (relocsize)
|
||||
addLoader(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff) >= relocsize ? "EXENOADJ" : "EXEADJUS",
|
||||
"EXERELO1",
|
||||
has_9a ? "EXEREL9A" : "",
|
||||
"EXERELO2",
|
||||
ih_exesize > 0xFE00 ? "EXEREBIG" : "",
|
||||
"EXERELO3",
|
||||
NULL
|
||||
);
|
||||
addLoader("EXEMAIN8",
|
||||
device_driver ? "DEVICEEND" : "",
|
||||
(flag & SS) ? "EXESTACK" : "",
|
||||
(flag & SP) ? "EXESTASP" : "",
|
||||
(flag & USEJUMP) ? "EXEJUMPF" : "",
|
||||
NULL
|
||||
);
|
||||
if (!(flag & USEJUMP))
|
||||
addLoader(ih.cs ? "EXERCSPO" : "",
|
||||
"EXERETIP",
|
||||
NULL
|
||||
);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
|
||||
addLoaderEpilogue(flag);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +325,9 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
||||
const upx_byte *relocs, const unsigned nrelocs,
|
||||
upx_byte *crel, bool *has_9a)
|
||||
{
|
||||
if (opt->exact)
|
||||
throwCantPackExact();
|
||||
|
||||
upx_byte * const crel_save = crel;
|
||||
unsigned i;
|
||||
unsigned seg_high = 0;
|
||||
@@ -311,7 +402,7 @@ unsigned optimize_relocs(upx_byte *b, const unsigned size,
|
||||
break;
|
||||
}
|
||||
unsigned offs = addr - es*16;
|
||||
if (offs >= 3 && b[es*16 + offs-3] == 0x9a)
|
||||
if (offs >= 3 && b[es*16 + offs-3] == 0x9a && offs > di + 3)
|
||||
{
|
||||
for (t = di; t < offs-3; t++)
|
||||
if (b[es*16+t] == 0x9a && get_le16(b+es*16+t+3) <= seg_high)
|
||||
@@ -388,7 +479,7 @@ void PackExe::pack(OutputFile *fo)
|
||||
for (ic = 0; ic < ih.relocs; ic++)
|
||||
{
|
||||
unsigned jc = get_le32(wr+4*ic);
|
||||
set_le32(wr+4*ic, (jc>>16)*16+(jc&0xffff));
|
||||
set_le32(wr+4*ic, ((jc>>16)*16+(jc&0xffff)) & 0xfffff);
|
||||
}
|
||||
qsort(wr,ih.relocs,4,le32_compare);
|
||||
relocsize = optimize_relocs(ibuf, ih_imagesize, wr, ih.relocs, w, &has_9a);
|
||||
@@ -416,11 +507,14 @@ void PackExe::pack(OutputFile *fo)
|
||||
// compress (max_match = 8192)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = MAXMATCH;
|
||||
compressWithFilters(&ft, 32, 0, NULL, &cconf);
|
||||
if (ph.max_run_found + ph.max_match_found > 0x8000)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 32, &cconf);
|
||||
|
||||
#ifdef TESTING
|
||||
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
||||
if (ph.max_run_found + ph.max_match_found > 0x8000)
|
||||
throwCantPack("decompressor limit exceeded, send a bugreport");
|
||||
|
||||
#if TESTING
|
||||
if (opt->debug.debug_level)
|
||||
{
|
||||
printf("image+relocs %d -> %d\n",ih_imagesize+relocsize,ph.c_len);
|
||||
@@ -484,15 +578,13 @@ void PackExe::pack(OutputFile *fo)
|
||||
}
|
||||
extra_info[eisize++] = (unsigned char) flag;
|
||||
|
||||
linker->defineSymbol("original_cs", ih.cs);
|
||||
linker->defineSymbol("original_ip", ih.ip);
|
||||
linker->defineSymbol("original_sp", ih.sp);
|
||||
linker->defineSymbol("original_ss", ih.ss);
|
||||
linker->defineSymbol("reloc_size",
|
||||
(ph.u_len <= DI_LIMIT || (ph.u_len & 0x7fff)
|
||||
>= relocsize ? 0 : MAXRELOCS) - relocsize);
|
||||
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
||||
linker->defineSymbol("decompressor_entry", (packedsize & 15) + 1);
|
||||
if (M_IS_NRV2B(ph.method) || M_IS_NRV2D(ph.method) || M_IS_NRV2E(ph.method))
|
||||
linker->defineSymbol("bx_magic", 0x7FFF + 0x10 * ((packedsize & 15) + 1));
|
||||
|
||||
unsigned decompressor_entry = 1 + (packedsize & 15);
|
||||
if (M_IS_LZMA(ph.method))
|
||||
decompressor_entry = 0x10;
|
||||
linker->defineSymbol("decompressor_entry", decompressor_entry);
|
||||
|
||||
// patch loader
|
||||
if (flag & USEJUMP)
|
||||
@@ -528,16 +620,18 @@ void PackExe::pack(OutputFile *fo)
|
||||
oh.m512 = outputlen & 511;
|
||||
oh.p512 = (outputlen + 511) >> 9;
|
||||
|
||||
oh.ip = device_driver ? getLoaderSection("EXEENTRY") - 2 : 0;
|
||||
const char *exeentry = M_IS_LZMA(ph.method) ? "LZMAENTRY" : "EXEENTRY";
|
||||
oh.ip = device_driver ? getLoaderSection(exeentry) - 2 : 0;
|
||||
|
||||
linker->relocate();
|
||||
defineDecompressorSymbols();
|
||||
relocateLoader();
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader,e_len);
|
||||
|
||||
//fprintf(stderr,"\ne_len=%x d_len=%x c_len=%x oo=%x ulen=%x destp=%x copys=%x images=%x",e_len,d_len,packedsize,ph.overlap_overhead,ph.u_len,destpara,copysize,ih_imagesize);
|
||||
|
||||
// write header + write loader + compressed file
|
||||
#ifdef TESTING
|
||||
#if TESTING
|
||||
if (opt->debug.debug_level)
|
||||
printf("\n%d %d %d %d\n",(int)sizeof(oh),e_len,packedsize,d_len);
|
||||
#endif
|
||||
@@ -578,7 +672,7 @@ int PackExe::canUnpack()
|
||||
return false;
|
||||
const off_t off = ih.headsize16 * 16;
|
||||
fi->seek(off, SEEK_SET);
|
||||
bool b = readPackHeader(256);
|
||||
bool b = readPackHeader(4096);
|
||||
return b && (off + (off_t) ph.c_len <= file_size);
|
||||
}
|
||||
|
||||
@@ -713,6 +807,69 @@ Linker* PackExe::newLinker() const
|
||||
return new ElfLinkerX86();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
memory layout at decompression time
|
||||
===================================
|
||||
|
||||
normal exe
|
||||
----------
|
||||
|
||||
a, at load time
|
||||
|
||||
(e - copying code, C - compressed data, d - decompressor+relocator,
|
||||
x - not specified, U - uncompressed code+data, R uncompressed relocation)
|
||||
|
||||
eeCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCdddd
|
||||
^ CS:0 ^ SS:0
|
||||
|
||||
b, after copying
|
||||
|
||||
xxxxxxxxxxxxxxxCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCdddd
|
||||
^ES:DI=0 ^ DS:SI=0 ^ CS=SS, IP in range 0..0xf
|
||||
|
||||
c, after uncompression
|
||||
|
||||
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURRdddd
|
||||
^ ES:DI
|
||||
|
||||
device driver
|
||||
-------------
|
||||
|
||||
the file has 2 entry points, CS:0 in device driver mode, and
|
||||
CS:exe_as_device_entry in normal mode. the code in section DEVICEENTRY
|
||||
sets up the same environment for section EXEENTRY, as it would see in normal
|
||||
execution mode.
|
||||
|
||||
lzma uncompression for normal exes
|
||||
----------------------------------
|
||||
|
||||
(n - nrv2b uncompressor, l - nrv2b compressed lzma + relocator code)
|
||||
|
||||
a, at load time
|
||||
|
||||
nneelllCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
|
||||
^ CS:0 ^ SS:0
|
||||
|
||||
b, after nrv2b
|
||||
|
||||
nneelllCCCCCCCCCCCCCCCCCCCCCCCCC dddd
|
||||
^ CS:0 ^ SS:0x10
|
||||
|
||||
after this, normal ee code runs
|
||||
|
||||
lzma + device driver
|
||||
--------------------
|
||||
|
||||
(D - device driver adapter)
|
||||
|
||||
a, at load time
|
||||
|
||||
DDnneelllCCCCCCCCCCCCCCCCCCCCCCCCC
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
|
||||
+14
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_EXE_H
|
||||
#define __UPX_P_EXE_H
|
||||
#define __UPX_P_EXE_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_EXE; }
|
||||
virtual const char *getName() const { return "dos/exe"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.exe" : "i286-dos16.exe"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.exe"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -68,11 +70,11 @@ protected:
|
||||
virtual int readFileHeader(void);
|
||||
|
||||
virtual int fillExeHeader(struct exe_header_t *) const;
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
void addLoaderEpilogue(int flag);
|
||||
|
||||
struct exe_header_t
|
||||
{
|
||||
__packed_struct(exe_header_t)
|
||||
LE16 ident;
|
||||
LE16 m512;
|
||||
LE16 p512;
|
||||
@@ -88,8 +90,7 @@ protected:
|
||||
LE16 relocoffs;
|
||||
char __[2]; // overlnum
|
||||
LE32 firstreloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
exe_header_t ih, oh;
|
||||
|
||||
@@ -109,6 +110,9 @@ protected:
|
||||
MINMEM = 16,
|
||||
MAXMEM = 32
|
||||
};
|
||||
|
||||
unsigned stack_for_lzma; // stack size required for lzma
|
||||
bool use_clear_dirty_stack;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+2146
-757
File diff suppressed because it is too large
Load Diff
+220
-83
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_ELF_H //{
|
||||
#define __UPX_P_LX_ELF_H
|
||||
#define __UPX_P_LX_ELF_H 1
|
||||
|
||||
|
||||
class PackLinuxElf : public PackUnix
|
||||
@@ -40,7 +40,7 @@ class PackLinuxElf : public PackUnix
|
||||
public:
|
||||
PackLinuxElf(InputFile *f);
|
||||
virtual ~PackLinuxElf();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
/*virtual void buildLoader(const Filter *);*/
|
||||
virtual bool canUnpackVersion(int version) const { return (version >= 11); }
|
||||
|
||||
protected:
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
// because they depend on Elf32 or Elf64 data structures, which differ.
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &) = 0; // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &) = 0; // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &) = 0; // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &) = 0; // append loader
|
||||
//virtual void pack4(OutputFile *, Filter &) = 0; // append pack header
|
||||
|
||||
@@ -61,21 +61,36 @@ protected:
|
||||
) = 0;
|
||||
virtual void defineSymbols(Filter const *);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
virtual void unpack(OutputFile *fo) = 0;
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
//virtual void const *elf_find_dynamic(unsigned) const = 0;
|
||||
virtual upx_uint64_t elf_unsigned_dynamic(unsigned) const = 0;
|
||||
|
||||
protected:
|
||||
unsigned e_phnum; /* Program header table entry count */
|
||||
char *file_image; // if ET_DYN investigation
|
||||
char const *dynstr; // from DT_STRTAB
|
||||
|
||||
unsigned sz_phdrs; // sizeof Phdr[]
|
||||
unsigned sz_elf_hdrs; // all Elf headers
|
||||
unsigned sz_pack2; // after pack2(), before loader
|
||||
unsigned sz_pack2a; // after pack2() of all PT_LOAD
|
||||
unsigned lg2_page; // log2(PAGE_SIZE)
|
||||
unsigned page_size; // 1u<<lg2_page
|
||||
unsigned xct_off; // shared library: file offset of SHT_EXECINSTR
|
||||
unsigned hatch_off; // file offset of escape hatch
|
||||
upx_uint64_t load_va; // PT_LOAD[0].p_vaddr
|
||||
upx_uint64_t xct_va; // minimum SHT_EXECINSTR virtual address
|
||||
|
||||
unsigned short e_machine;
|
||||
unsigned char ei_class;
|
||||
unsigned char ei_data;
|
||||
unsigned char ei_osabi;
|
||||
char const *osabi_note;
|
||||
|
||||
unsigned char const *buildid_data;
|
||||
int o_elf_shnum; // num output Shdrs
|
||||
static unsigned char o_shstrtab[];
|
||||
};
|
||||
|
||||
class PackLinuxElf32 : public PackLinuxElf
|
||||
@@ -90,13 +105,12 @@ protected:
|
||||
|
||||
// These ARM routines are essentially common to big/little endian,
|
||||
// but the class hierarchy splits after this class.
|
||||
virtual int ARM_buildLoader(Filter const *ft, bool isBE);
|
||||
virtual void ARM_defineSymbols(Filter const *ft);
|
||||
virtual void ARM_updateLoader(OutputFile *);
|
||||
virtual void ARM_pack1(OutputFile *, bool isBE);
|
||||
virtual int ARM_is_QNX(void);
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
@@ -106,7 +120,7 @@ protected:
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual int buildLinuxLoader(
|
||||
virtual void buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
@@ -121,48 +135,83 @@ protected:
|
||||
virtual off_t getbase(const Elf32_Phdr *phdr, int e_phnum) const;
|
||||
|
||||
static unsigned elf_hash(char const *) /*const*/;
|
||||
virtual void const *elf_find_dynamic(unsigned) const;
|
||||
static unsigned gnu_hash(char const *) /*const*/;
|
||||
virtual Elf32_Sym const *elf_lookup(char const *) const;
|
||||
virtual unsigned elf_get_offset_from_address(unsigned) const;
|
||||
Elf32_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf32_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
Elf32_Dyn const *elf_has_dynamic(unsigned) const;
|
||||
upx_uint64_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf32_Ehdr ehdri; // from input file
|
||||
Elf32_Phdr *phdri; // for input file
|
||||
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
|
||||
unsigned note_size; // total size of PT_NOTEs
|
||||
Elf32_Shdr const *shdri; // from input file
|
||||
unsigned page_mask; // AND clears the offset-within-page
|
||||
|
||||
Elf32_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
unsigned int const *gashtab; // from DT_GNU_HASH
|
||||
Elf32_Sym const *dynsym; // from DT_SYMTAB
|
||||
char const *shstrtab; // via Elf32_Shdr
|
||||
int n_elf_shnum; // via e_shnum
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf32_Shdr const *sec_strndx;
|
||||
Elf32_Shdr const *sec_dynsym;
|
||||
Elf32_Shdr const *sec_dynstr;
|
||||
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(cprElfHdrNetBSD)
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf32_Phdr phdr[4];
|
||||
unsigned char notes[512];
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdrNetBSD elfout;
|
||||
|
||||
__packed_struct(cprElfShdr3)
|
||||
Elf32_Shdr shdr[3];
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfShdr3 shdrout;
|
||||
|
||||
struct Elf32_Nhdr {
|
||||
unsigned namesz;
|
||||
unsigned descsz;
|
||||
unsigned type;
|
||||
//unsigned char body[0];
|
||||
};
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdrNetBSD) == 52 + 4*32 + 512)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdrNetBSD)
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
struct Elf32_Note {
|
||||
unsigned namesz; // 8
|
||||
unsigned descsz; // 4
|
||||
unsigned type; // 1
|
||||
char text[0x18 - 4*4]; // "OpenBSD"
|
||||
unsigned end; // 0
|
||||
} elfnote;
|
||||
};
|
||||
|
||||
|
||||
@@ -172,13 +221,13 @@ class PackLinuxElf64 : public PackLinuxElf
|
||||
public:
|
||||
PackLinuxElf64(InputFile *f);
|
||||
virtual ~PackLinuxElf64();
|
||||
/*virtual int buildLoader(const Filter *);*/
|
||||
/*virtual void buildLoader(const Filter *);*/
|
||||
|
||||
protected:
|
||||
virtual int checkEhdr(Elf64_Ehdr const *ehdr) const;
|
||||
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append pack header
|
||||
virtual void unpack(OutputFile *fo);
|
||||
@@ -188,7 +237,7 @@ protected:
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
virtual int buildLinuxLoader(
|
||||
virtual void buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
@@ -201,76 +250,107 @@ protected:
|
||||
virtual unsigned find_LOAD_gap(Elf64_Phdr const *const phdri, unsigned const k,
|
||||
unsigned const e_phnum);
|
||||
|
||||
virtual upx_uint64_t elf_get_offset_from_address(upx_uint64_t) const;
|
||||
Elf64_Shdr const *elf_find_section_name(char const *) const;
|
||||
Elf64_Shdr const *elf_find_section_type(unsigned) const;
|
||||
void const *elf_find_dynamic(unsigned) const;
|
||||
Elf64_Dyn const *elf_has_dynamic(unsigned) const;
|
||||
upx_uint64_t elf_unsigned_dynamic(unsigned) const;
|
||||
|
||||
protected:
|
||||
Elf64_Ehdr ehdri; // from input file
|
||||
Elf64_Phdr *phdri; // for input file
|
||||
unsigned char *note_body; // concatenated contents of PT_NOTEs, if any
|
||||
unsigned note_size; // total size of PT_NOTEs
|
||||
Elf64_Shdr const *shdri; // from input file
|
||||
upx_uint64_t page_mask; // AND clears the offset-within-page
|
||||
|
||||
struct cprElfHdr1 {
|
||||
Elf64_Dyn const *dynseg; // from PT_DYNAMIC
|
||||
unsigned int const *hashtab; // from DT_HASH
|
||||
unsigned int const *gashtab; // from DT_GNU_HASH
|
||||
Elf64_Sym const *dynsym; // from DT_SYMTAB
|
||||
char const *shstrtab; // via Elf64_Shdr
|
||||
int n_elf_shnum; // via e_shnum
|
||||
|
||||
Elf64_Shdr const *sec_strndx;
|
||||
Elf64_Shdr const *sec_dynsym;
|
||||
Elf64_Shdr const *sec_dynstr;
|
||||
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
__packed_struct(cprElfHdr4)
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Phdr phdr[4];
|
||||
l_info linfo;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr4 elfout;
|
||||
|
||||
__packed_struct(cprElfShdr3)
|
||||
Elf64_Shdr shdr[3];
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfShdr3 shdrout;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 64 + 1*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 64 + 2*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 64 + 3*56 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr4) == 64 + 4*56 + 12)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr4)
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf32Be : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
PackLinuxElf32Be(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf32Le : public PackLinuxElf32
|
||||
{
|
||||
typedef PackLinuxElf32 super;
|
||||
protected:
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
PackLinuxElf32Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
class PackLinuxElf64Le : public PackLinuxElf64
|
||||
{
|
||||
typedef PackLinuxElf64 super;
|
||||
protected:
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) { }
|
||||
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
PackLinuxElf64Le(InputFile *f) : super(f) {
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
e_phnum = get_te16(&ehdri.e_phnum);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf64amd
|
||||
**************************************************************************/
|
||||
@@ -283,16 +363,18 @@ public:
|
||||
virtual ~PackLinuxElf64amd();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF64_AMD; }
|
||||
virtual const char *getName() const { return "linux/ElfAMD"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "amd64-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
virtual bool canPack();
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
//virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf32ppc
|
||||
**************************************************************************/
|
||||
@@ -305,13 +387,15 @@ public:
|
||||
virtual ~PackLinuxElf32ppc();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFPPC32; }
|
||||
virtual const char *getName() const { return "linux/ElfPPC"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual Linker* newLinker() const;
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elf386
|
||||
**************************************************************************/
|
||||
@@ -324,14 +408,13 @@ public:
|
||||
virtual ~PackLinuxElf32x86();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF_i386; }
|
||||
virtual const char *getName() const { return "linux/elf386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void addStubEntrySections(Filter const *);
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void defineSymbols(Filter const *);
|
||||
@@ -349,7 +432,7 @@ public:
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
};
|
||||
|
||||
class PackFreeBSDElf32x86 : public PackBSDElf32x86
|
||||
@@ -358,14 +441,24 @@ class PackFreeBSDElf32x86 : public PackBSDElf32x86
|
||||
public:
|
||||
PackFreeBSDElf32x86(InputFile *f);
|
||||
virtual ~PackFreeBSDElf32x86();
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-freebsd.elf"; }
|
||||
};
|
||||
|
||||
class PackNetBSDElf32x86 : public PackBSDElf32x86
|
||||
class PackNetBSDElf32x86 : public PackLinuxElf32x86
|
||||
{
|
||||
typedef PackBSDElf32x86 super;
|
||||
typedef PackLinuxElf32x86 super;
|
||||
public:
|
||||
PackNetBSDElf32x86(InputFile *f);
|
||||
virtual ~PackNetBSDElf32x86();
|
||||
virtual const char *getName() const { return "netbsd/elf386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-netbsd.elf"; }
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
unsigned const brka
|
||||
);
|
||||
};
|
||||
|
||||
class PackOpenBSDElf32x86 : public PackBSDElf32x86
|
||||
@@ -374,9 +467,11 @@ class PackOpenBSDElf32x86 : public PackBSDElf32x86
|
||||
public:
|
||||
PackOpenBSDElf32x86(InputFile *f);
|
||||
virtual ~PackOpenBSDElf32x86();
|
||||
virtual const char *getName() const { return "opnbsd/elf386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-openbsd.elf"; }
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void generateElfHdr(
|
||||
OutputFile *,
|
||||
void const *proto,
|
||||
@@ -384,6 +479,7 @@ protected:
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// linux/elfarm
|
||||
**************************************************************************/
|
||||
@@ -394,15 +490,16 @@ class PackLinuxElf32armLe : public PackLinuxElf32Le
|
||||
public:
|
||||
PackLinuxElf32armLe(InputFile *f);
|
||||
virtual ~PackLinuxElf32armLe();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMLE; }
|
||||
virtual const char *getName() const { return "linux/armLE"; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEL; }
|
||||
virtual const char *getName() const { return "linux/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "arm-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
@@ -413,19 +510,59 @@ class PackLinuxElf32armBe : public PackLinuxElf32Be
|
||||
public:
|
||||
PackLinuxElf32armBe(InputFile *f);
|
||||
virtual ~PackLinuxElf32armBe();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMBE; }
|
||||
virtual const char *getName() const { return "linux/armBE"; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_ARMEB; }
|
||||
virtual const char *getName() const { return "linux/armeb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armeb-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
class PackLinuxElf32mipseb : public PackLinuxElf32Be
|
||||
{
|
||||
typedef PackLinuxElf32Be super;
|
||||
public:
|
||||
PackLinuxElf32mipseb(InputFile *f);
|
||||
virtual ~PackLinuxElf32mipseb();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEB; }
|
||||
virtual const char *getName() const { return "linux/mipseb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "mips-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
class PackLinuxElf32mipsel : public PackLinuxElf32Le
|
||||
{
|
||||
typedef PackLinuxElf32Le super;
|
||||
public:
|
||||
PackLinuxElf32mipsel(InputFile *f);
|
||||
virtual ~PackLinuxElf32mipsel();
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELF32_MIPSEL; }
|
||||
virtual const char *getName() const { return "linux/mipsel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "mipsel-linux.elf"; }
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void buildLoader(const Filter *);
|
||||
virtual void updateLoader(OutputFile *);
|
||||
virtual void defineSymbols(Filter const *);
|
||||
};
|
||||
|
||||
|
||||
#endif /*} already included */
|
||||
|
||||
|
||||
|
||||
+46
-42
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2001-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2001-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -57,6 +57,7 @@
|
||||
PackLinuxI386::PackLinuxI386(InputFile *f) : super(f),
|
||||
ei_osabi(Elf32_Ehdr::ELFOSABI_LINUX), osabi_note(NULL)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
}
|
||||
|
||||
PackBSDI386::PackBSDI386(InputFile *f) : super(f)
|
||||
@@ -99,7 +100,7 @@ const int *PackLinuxI386::getFilters() const
|
||||
0x83, 0x86, 0x80, 0x84, 0x87, 0x81, 0x82, 0x85,
|
||||
0x24, 0x16, 0x13, 0x14, 0x11, 0x25, 0x15, 0x12,
|
||||
#endif
|
||||
-1 };
|
||||
FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
@@ -131,8 +132,8 @@ PackLinuxI386::generateElfHdr(
|
||||
unsigned const brka
|
||||
)
|
||||
{
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)&elfout;
|
||||
cprElfHdr2 *const h2 = (cprElfHdr2 *)(void *)&elfout;
|
||||
cprElfHdr3 *const h3 = (cprElfHdr3 *)(void *)&elfout;
|
||||
memcpy(h3, proto, sizeof(*h3)); // reads beyond, but OK
|
||||
|
||||
assert(h2->ehdr.e_phoff == sizeof(Elf32_Ehdr));
|
||||
@@ -182,7 +183,7 @@ PackLinuxI386::pack1(OutputFile *fo, Filter &)
|
||||
// create a pseudo-unique program id for our paranoid stub
|
||||
progid = getRandomId();
|
||||
|
||||
generateElfHdr(fo, linux_i386exec_fold, 0);
|
||||
generateElfHdr(fo, stub_i386_linux_elf_execve_fold, 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -191,7 +192,7 @@ PackBSDI386::pack1(OutputFile *fo, Filter &)
|
||||
// create a pseudo-unique program id for our paranoid stub
|
||||
progid = getRandomId();
|
||||
|
||||
generateElfHdr(fo, bsd_i386exec_fold, 0);
|
||||
generateElfHdr(fo, stub_i386_bsd_elf_execve_fold, 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -203,7 +204,7 @@ PackLinuxI386::pack4(OutputFile *fo, Filter &ft)
|
||||
((elfout.ehdr.e_phnum==3) ? (unsigned) elfout.phdr[2].p_memsz : 0) ;
|
||||
unsigned nw = fo->getBytesWritten();
|
||||
elfout.phdr[0].p_filesz = nw;
|
||||
nw = -(-elfout.phdr[0].p_align & -nw); // ALIGN_UP
|
||||
nw = 0u-((0u-elfout.phdr[0].p_align) & (0u-nw)); // ALIGN_UP
|
||||
super::pack4(fo, ft); // write PackHeader and overlay_offset
|
||||
set_stub_brk(&elfout.phdr[1], nw + elfout.phdr[0].p_vaddr);
|
||||
|
||||
@@ -292,7 +293,7 @@ Linker *PackLinuxI386::newLinker() const
|
||||
return new ElfLinkerX86;
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
PackLinuxI386::buildLinuxLoader(
|
||||
upx_byte const *const proto,
|
||||
unsigned const szproto,
|
||||
@@ -372,13 +373,14 @@ PackLinuxI386::buildLinuxLoader(
|
||||
addLoader("IDENTSTR", NULL);
|
||||
addLoader("LEXEC020", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
freezeLoader();
|
||||
if (ph.method == M_LZMA) {
|
||||
if (M_IS_LZMA(ph.method)) {
|
||||
const lzma_compress_result_t *res = &ph.compress_result.result_lzma;
|
||||
unsigned const properties = // lc, lp, pb, dummy
|
||||
upx_uint32_t properties = // lc, lp, pb, dummy
|
||||
(res->lit_context_bits << 0) |
|
||||
(res->lit_pos_bits << 8) |
|
||||
(res->pos_bits << 16);
|
||||
if (linker->bele->isBE()) // big endian - bswap32
|
||||
acc_swab32s(&properties);
|
||||
linker->defineSymbol("lzma_properties", properties);
|
||||
// -2 for properties
|
||||
linker->defineSymbol("lzma_c_len", ph.c_len - 2);
|
||||
@@ -393,16 +395,15 @@ PackLinuxI386::buildLinuxLoader(
|
||||
linker->defineSymbol("NMRU", mru - is_pwr2);
|
||||
}
|
||||
}
|
||||
linker->relocate();
|
||||
return getLoaderSize();
|
||||
relocateLoader();
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
PackLinuxI386::buildLoader(Filter const *ft)
|
||||
{
|
||||
unsigned const sz_fold = sizeof(linux_i386exec_fold);
|
||||
unsigned const sz_fold = sizeof(stub_i386_linux_elf_execve_fold);
|
||||
MemBuffer buf(sz_fold);
|
||||
memcpy(buf, linux_i386exec_fold, sz_fold);
|
||||
memcpy(buf, stub_i386_linux_elf_execve_fold, sz_fold);
|
||||
|
||||
// patch loader
|
||||
// note: we only can use /proc/<pid>/fd when exetype > 0.
|
||||
@@ -412,17 +413,17 @@ PackLinuxI386::buildLoader(Filter const *ft)
|
||||
patch_le32(buf,sz_fold,"UPX3",progid);
|
||||
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
|
||||
|
||||
return buildLinuxLoader(
|
||||
linux_i386exec_loader, sizeof(linux_i386exec_loader),
|
||||
buildLinuxLoader(
|
||||
stub_i386_linux_elf_execve_entry, sizeof(stub_i386_linux_elf_execve_entry),
|
||||
buf, sz_fold, ft );
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
PackBSDI386::buildLoader(Filter const *ft)
|
||||
{
|
||||
unsigned const sz_fold = sizeof(bsd_i386exec_fold);
|
||||
unsigned const sz_fold = sizeof(stub_i386_bsd_elf_execve_fold);
|
||||
MemBuffer buf(sz_fold);
|
||||
memcpy(buf, bsd_i386exec_fold, sz_fold);
|
||||
memcpy(buf, stub_i386_bsd_elf_execve_fold, sz_fold);
|
||||
|
||||
// patch loader
|
||||
// note: we only can use /proc/<pid>/fd when exetype > 0.
|
||||
@@ -432,8 +433,8 @@ PackBSDI386::buildLoader(Filter const *ft)
|
||||
patch_le32(buf,sz_fold,"UPX3",progid);
|
||||
patch_le32(buf,sz_fold,"UPX2",exetype > 0 ? 0 : 0x7fffffff);
|
||||
|
||||
return buildLinuxLoader(
|
||||
bsd_i386exec_loader, sizeof(bsd_i386exec_loader),
|
||||
buildLinuxLoader(
|
||||
stub_i386_bsd_elf_execve_entry, sizeof(stub_i386_bsd_elf_execve_entry),
|
||||
buf, sz_fold, ft );
|
||||
}
|
||||
|
||||
@@ -448,8 +449,8 @@ int PackLinuxI386::getLoaderPrefixSize() const
|
||||
// some ELF utitlity functions
|
||||
**************************************************************************/
|
||||
|
||||
// basic check of an Linux ELF Ehdr
|
||||
int PackLinuxI386::checkEhdr(const Elf32_Ehdr *ehdr) const
|
||||
// basic check of a Linux ELF Ehdr
|
||||
int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const
|
||||
{
|
||||
const unsigned char * const buf = ehdr->e_ident;
|
||||
|
||||
@@ -499,7 +500,7 @@ bool PackLinuxI386::canPack()
|
||||
if (exetype != 0)
|
||||
return super::canPack();
|
||||
|
||||
Elf32_Ehdr ehdr;
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
unsigned char *buf = ehdr.e_ident;
|
||||
|
||||
fi->seek(0, SEEK_SET);
|
||||
@@ -525,28 +526,31 @@ bool PackLinuxI386::canPack()
|
||||
ei_osabi = osabi0; // Proudly declares its osabi in Ehdr.
|
||||
break;
|
||||
default:
|
||||
unsigned const e_phnum = get_native16(&ehdr.e_phnum);
|
||||
unsigned const e_phnum = get_te16(&ehdr.e_phnum);
|
||||
if (e_phnum<=(512/sizeof(Elf32_Phdr))) {
|
||||
char buf2[512];
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(buf2, sizeof(buf2));
|
||||
union {
|
||||
unsigned char buf2[512];
|
||||
//Elf32_Phdr phdr;
|
||||
} u;
|
||||
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(u.buf2, sizeof(u.buf2));
|
||||
fi->seek(0, SEEK_SET);
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr const *)buf2;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) u.buf2;
|
||||
for (unsigned j=0; j < e_phnum; ++phdr, ++j) {
|
||||
if (phdr->PT_NOTE == get_native32(&phdr->p_type)) {
|
||||
unsigned const offset = get_native32(&phdr->p_offset);
|
||||
if (phdr->PT_NOTE == get_te32(&phdr->p_type)) {
|
||||
unsigned const offset = get_te32(&phdr->p_offset);
|
||||
struct Elf32_Note note; memset(¬e, 0, sizeof(note));
|
||||
fi->seek(offset, SEEK_SET);
|
||||
fi->readx(¬e, sizeof(note));
|
||||
fi->seek(0, SEEK_SET);
|
||||
if (4==get_native32(¬e.descsz)
|
||||
&& 1==get_native32(¬e.type)
|
||||
if (4==get_te32(¬e.descsz)
|
||||
&& 1==get_te32(¬e.type)
|
||||
&& 0==note.end ) {
|
||||
if (0==strcmp("NetBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("NetBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_NETBSD;
|
||||
break;
|
||||
}
|
||||
if (0==strcmp("OpenBSD", (char const *)¬e.text)) {
|
||||
if (0==strcmp("OpenBSD", (char const *)note.text)) {
|
||||
ei_osabi = Elf32_Ehdr::ELFOSABI_OPENBSD;
|
||||
break;
|
||||
}
|
||||
@@ -597,11 +601,11 @@ void PackLinuxI386::patchLoaderChecksum()
|
||||
// checksum for loader + p_info
|
||||
lp->l_checksum = 0;
|
||||
lp->l_magic = UPX_ELF_MAGIC;
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
set_te16(&lp->l_lsize, (unsigned short) lsize);
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+26
-18
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_EXC_H
|
||||
#define __UPX_P_LX_EXC_H
|
||||
#define __UPX_P_LX_EXC_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -49,9 +49,10 @@ public:
|
||||
);
|
||||
virtual int getFormat() const { return UPX_F_LINUX_i386; }
|
||||
virtual const char *getName() const { return "linux/386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.execve"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
|
||||
virtual bool canPack();
|
||||
|
||||
@@ -64,7 +65,7 @@ protected:
|
||||
// loader util
|
||||
virtual Linker* newLinker() const;
|
||||
virtual int getLoaderPrefixSize() const;
|
||||
virtual int buildLinuxLoader(
|
||||
virtual void buildLinuxLoader(
|
||||
upx_byte const *const proto, // assembly-only sections
|
||||
unsigned const szproto,
|
||||
upx_byte const *const fold, // linked assembly + C section
|
||||
@@ -78,7 +79,7 @@ protected:
|
||||
virtual void updateLoader(OutputFile *);
|
||||
|
||||
// ELF util
|
||||
virtual int checkEhdr(const Elf32_Ehdr *ehdr) const;
|
||||
virtual int checkEhdr(const Elf_LE32_Ehdr *ehdr) const;
|
||||
|
||||
enum {
|
||||
UPX_ELF_MAGIC = 0x5850557f // "\x7fUPX"
|
||||
@@ -86,26 +87,23 @@ protected:
|
||||
|
||||
unsigned n_mru;
|
||||
|
||||
struct cprElfHdr1 {
|
||||
__packed_struct(cprElfHdr1)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[1];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr2 {
|
||||
__packed_struct(cprElfHdr2)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[2];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct cprElfHdr3 {
|
||||
__packed_struct(cprElfHdr3)
|
||||
Elf_LE32_Ehdr ehdr;
|
||||
Elf_LE32_Phdr phdr[3];
|
||||
l_info linfo;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
cprElfHdr3 elfout;
|
||||
|
||||
@@ -119,6 +117,15 @@ protected:
|
||||
|
||||
unsigned char ei_osabi;
|
||||
char const *osabi_note;
|
||||
|
||||
static void compileTimeAssertions() {
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr1) == 52 + 1*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr2) == 52 + 2*32 + 12)
|
||||
COMPILE_TIME_ASSERT(sizeof(cprElfHdr3) == 52 + 3*32 + 12)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr1)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr2)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(cprElfHdr3)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -128,12 +135,13 @@ class PackBSDI386 : public PackLinuxI386
|
||||
public:
|
||||
PackBSDI386(InputFile *f);
|
||||
virtual int getFormat() const { return UPX_F_BSD_i386; }
|
||||
virtual const char *getName() const { return "*BSD/386"; }
|
||||
virtual const char *getName() const { return "BSD/386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-bsd.elf.execve"; }
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
};
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
+26
-24
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -114,7 +114,7 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||
h3.phdr[2].p_align = 1;
|
||||
|
||||
if (opt->o_unix.make_ptinterp) { // unusual "once per release"
|
||||
elfout = h3;
|
||||
*(cprElfHdr3 *)(void *)&elfout = h3;
|
||||
elfout.ehdr.e_phnum = 1;
|
||||
fo->write(&elfout, elfout.ehdr.e_ehsize + elfout.ehdr.e_phentsize);
|
||||
}
|
||||
@@ -124,12 +124,12 @@ void PackLinuxElf32x86interp::pack1(OutputFile *fo, Filter &)
|
||||
#undef E
|
||||
}
|
||||
|
||||
void PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
|
||||
int PackLinuxElf32x86interp::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
return; // ignore current input file!
|
||||
return 1; // ignore current input file!
|
||||
}
|
||||
super::pack2(fo, ft);
|
||||
return super::pack2(fo, ft);
|
||||
}
|
||||
|
||||
#undef PAGE_MASK
|
||||
@@ -147,8 +147,8 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
}
|
||||
elfout.phdr[0].p_paddr = elfout.phdr[0].p_vaddr = base - sz;
|
||||
if (opt->o_unix.make_ptinterp) {
|
||||
initLoader(linux_i386pti_loader, sizeof(linux_i386pti_loader));
|
||||
linker->addSection("FOLDEXEC", linux_i386pti_fold, sizeof(linux_i386pti_fold), 0);
|
||||
initLoader(stub_i386_linux_elf_interp_entry, sizeof(stub_i386_linux_elf_interp_entry));
|
||||
linker->addSection("FOLDEXEC", stub_i386_linux_elf_interp_fold, sizeof(stub_i386_linux_elf_interp_fold), 0);
|
||||
|
||||
addLoader("LXPTI000", NULL);
|
||||
|
||||
@@ -164,9 +164,9 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
ph.method = M_NRV2E_LE32; addLoader(getDecompressorSections(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI043", NULL);
|
||||
ph.method = M_CL1B_LE32; addLoader(getDecompressorSections(), NULL);
|
||||
addLoader("LXPTI090", NULL);
|
||||
//addLoader("LXPTI043", NULL);
|
||||
//ph.method = M_CL1B_LE32; addLoader(getDecompressorSections(), NULL);
|
||||
//addLoader("LXPTI090", NULL);
|
||||
|
||||
addLoader("LXPTI091", NULL);
|
||||
|
||||
@@ -182,7 +182,6 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
|
||||
addLoader("LXPTI200", NULL);
|
||||
addLoader("FOLDEXEC", NULL);
|
||||
freezeLoader();
|
||||
upx_byte const *p = getLoader();
|
||||
lsize = getLoaderSize();
|
||||
updateLoader(fo);
|
||||
@@ -198,15 +197,18 @@ void PackLinuxElf32x86interp::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
{
|
||||
#define MAX_INTERP_HDR 512
|
||||
char bufehdr[MAX_INTERP_HDR];
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *)bufehdr;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *)(1+ehdr);
|
||||
union {
|
||||
unsigned char buf[MAX_INTERP_HDR];
|
||||
//struct { Elf32_Ehdr ehdr; Elf32_Phdr phdr; } e;
|
||||
} u;
|
||||
Elf32_Ehdr *const ehdr = (Elf32_Ehdr *) u.buf;
|
||||
Elf32_Phdr const *phdr = (Elf32_Phdr *) (u.buf + sizeof(*ehdr));
|
||||
|
||||
unsigned szb_info = sizeof(b_info);
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(bufehdr, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_native32(&ehdr->e_entry);
|
||||
fi->readx(u.buf, MAX_INTERP_HDR);
|
||||
unsigned const e_entry = get_te32(&ehdr->e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
@@ -215,16 +217,16 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
fi->seek(overlay_offset, SEEK_SET);
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
unsigned orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
unsigned orig_file_size = get_te32(&hbuf.p_filesize);
|
||||
blocksize = get_te32(&hbuf.p_blocksize);
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
|
||||
ibuf.alloc(blocksize + OVERHEAD);
|
||||
b_info bhdr; memset(&bhdr, 0, sizeof(bhdr));
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = get_native32(&bhdr.sz_cpr);
|
||||
ph.u_len = get_te32(&bhdr.sz_unc);
|
||||
ph.c_len = get_te32(&bhdr.sz_cpr);
|
||||
ph.filter_cto = bhdr.b_cto8;
|
||||
|
||||
// Uncompress Ehdr and Phdrs.
|
||||
@@ -278,7 +280,7 @@ void PackLinuxElf32x86interp::unpack(OutputFile *fo)
|
||||
|
||||
// check for end-of-file
|
||||
fi->readx(&bhdr, szb_info);
|
||||
unsigned const sz_unc = ph.u_len = get_native32(&bhdr.sz_unc);
|
||||
unsigned const sz_unc = ph.u_len = get_te32(&bhdr.sz_unc);
|
||||
|
||||
if (sz_unc == 0) { // uncompressed size 0 -> EOF
|
||||
// note: magic is always stored le32
|
||||
|
||||
+7
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_INTERP_H //{
|
||||
#define __UPX_P_LX_INTERP_H
|
||||
#define __UPX_P_LX_INTERP_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -47,13 +47,14 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_ELFI_i386; }
|
||||
virtual const char *getName() const { return "linux/elfi386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.interp"; }
|
||||
|
||||
virtual bool canPack();
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
protected:
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // build loader
|
||||
};
|
||||
|
||||
|
||||
+12
-12
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -71,12 +71,12 @@ umax(unsigned a, unsigned b)
|
||||
return a;
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
{
|
||||
unsigned const sz_fold = sizeof(linux_i386sh_fold);
|
||||
unsigned const sz_fold = sizeof(stub_i386_linux_elf_shell_fold);
|
||||
MemBuffer buf(sz_fold);
|
||||
memcpy(buf, linux_i386sh_fold, sz_fold);
|
||||
memcpy(buf, stub_i386_linux_elf_shell_fold, sz_fold);
|
||||
|
||||
checkPatch(NULL, 0, 0, 0); // reset
|
||||
patch_le32(buf,sz_fold,"UPX3",l_shname);
|
||||
@@ -85,13 +85,13 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
// get fresh filter
|
||||
Filter fold_ft = *ft;
|
||||
fold_ft.init(ft->id, ft->addvalue);
|
||||
int preferred_ctos[2] = {ft->cto, -1};
|
||||
int preferred_ctos[2] = { ft->cto, -1 };
|
||||
fold_ft.preferred_ctos = preferred_ctos;
|
||||
|
||||
// filter
|
||||
optimizeFilter(&fold_ft, buf, sz_fold);
|
||||
unsigned fold_hdrlen = sizeof(l_info) + sizeof(Elf32_Ehdr) +
|
||||
sizeof(Elf32_Phdr) * get_native32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
|
||||
sizeof(Elf32_Phdr) * get_te32(&((Elf32_Ehdr const *)(void *)buf)->e_phnum);
|
||||
if (0 == get_le32(fold_hdrlen + buf)) {
|
||||
// inconsistent SIZEOF_HEADERS in *.lds (ld, binutils)
|
||||
fold_hdrlen = umax(0x80, fold_hdrlen);
|
||||
@@ -99,8 +99,8 @@ PackLinuxI386sh::buildLoader(Filter const *ft)
|
||||
bool success = fold_ft.filter(buf + fold_hdrlen, sz_fold - fold_hdrlen);
|
||||
UNUSED(success);
|
||||
|
||||
return buildLinuxLoader(
|
||||
linux_i386sh_loader, sizeof(linux_i386sh_loader),
|
||||
buildLinuxLoader(
|
||||
stub_i386_linux_elf_shell_entry, sizeof(stub_i386_linux_elf_shell_entry),
|
||||
buf, sz_fold, ft );
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ bool PackLinuxI386sh::canPack()
|
||||
void
|
||||
PackLinuxI386sh::pack1(OutputFile *fo, Filter &)
|
||||
{
|
||||
generateElfHdr(fo, linux_i386sh_fold, 0x08048000);
|
||||
generateElfHdr(fo, stub_i386_linux_elf_shell_fold, 0x08048000);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+7
-6
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2000-2006 John F. Reiser
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2000-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_LX_SH_H //{
|
||||
#define __UPX_P_LX_SH_H
|
||||
#define __UPX_P_LX_SH_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -47,8 +47,9 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_LINUX_SH_i386; }
|
||||
virtual const char *getName() const { return "linux/sh386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.elf.shell"; }
|
||||
virtual const int *getFilters() const { return NULL; }
|
||||
virtual int buildLoader(const Filter *);
|
||||
virtual void buildLoader(const Filter *);
|
||||
|
||||
virtual void pack1(OutputFile *fo, Filter &ft);
|
||||
virtual void pack3(OutputFile *fo, Filter &ft);
|
||||
|
||||
+1419
-134
File diff suppressed because it is too large
Load Diff
+817
-136
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
||||
/* p_mach_enum.h --
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 2007-2013 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// Use the preprocessor to work around
|
||||
// - that the types embedding these enums have to be PODs, and
|
||||
// deriving from an empty base class (which is the usual C++ way
|
||||
// of "importing" enums) does not yield a POD any more
|
||||
// - that older compilers do not correctly perform EBCO
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef WANT_MACH_HEADER_ENUM /*{*/
|
||||
#undef WANT_MACH_HEADER_ENUM
|
||||
enum { // magic
|
||||
MH_MAGIC = 0xfeedface
|
||||
};
|
||||
enum { // cputype
|
||||
CPU_TYPE_I386 = 7,
|
||||
CPU_TYPE_X86_64 = 0x01000007,
|
||||
CPU_TYPE_ARM = 12,
|
||||
CPU_TYPE_POWERPC = 0x00000012,
|
||||
CPU_TYPE_POWERPC64 = 0x01000012
|
||||
};
|
||||
enum { // cpusubtype
|
||||
CPU_SUBTYPE_ARM_ALL = 0,
|
||||
CPU_SUBTYPE_ARM_V4T = 5,
|
||||
CPU_SUBTYPE_ARM_V6 = 6
|
||||
};
|
||||
enum { // filetype
|
||||
MH_EXECUTE = 2,
|
||||
MH_DYLIB = 6,
|
||||
MH_BUNDLE = 8 /* dynamically bound bundle file */
|
||||
};
|
||||
enum { // flags
|
||||
MH_NOUNDEFS = 1,
|
||||
MH_DYLDLINK = 4 /* code signing demands this */
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_SEGMENT_ENUM /*{*/
|
||||
#undef WANT_MACH_SEGMENT_ENUM
|
||||
enum { // cmd
|
||||
LC_SEGMENT = 0x1,
|
||||
LC_SYMTAB = 0x2,
|
||||
LC_THREAD = 0x4,
|
||||
LC_UNIXTHREAD = 0x5,
|
||||
LC_DYSYMTAB = 0xb,
|
||||
LC_LOAD_DYLIB = 0xc,
|
||||
LC_ID_DYLIB = 0xd,
|
||||
LC_LOAD_DYLINKER = 0xe,
|
||||
LC_ROUTINES = 0x11,
|
||||
LC_TWOLEVEL_HINTS= 0x16,
|
||||
LC_SEGMENT_64 = 0x19,
|
||||
LC_ROUTINES_64 = 0x1a,
|
||||
LC_UUID = 0x1b,
|
||||
LC_RPATH = 0x1c,
|
||||
LC_CODE_SIGNATURE = 0x1d,
|
||||
LC_SEGMENT_SPLIT_INFO = 0x1e,
|
||||
LC_REEXPORT_DYLIB = 0x1f,
|
||||
LC_LAZY_LOAD_DYLIB= 0X20,
|
||||
LC_ENCRYPTION_INFO= 0X21,
|
||||
LC_DYLD_INFO = 0X22, // compressed dyld information (10.6.x)
|
||||
LC_REQ_DYLD = 0x80000000 // OR'ed ==> must not ignore
|
||||
};
|
||||
enum { // maxprot
|
||||
VM_PROT_READ = 1,
|
||||
VM_PROT_WRITE = 2,
|
||||
VM_PROT_EXECUTE = 4
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_SECTION_ENUM /*{*/
|
||||
#undef WANT_MACH_SECTION_ENUM
|
||||
enum { // section type (low byte only)
|
||||
S_REGULAR = 0,
|
||||
S_ZEROFILL,
|
||||
S_CSTRING_LITERALS,
|
||||
S_4BYTE_LITERALS,
|
||||
S_8BYTE_LITERALS,
|
||||
S_LITERAL_POINTERS,
|
||||
S_NON_LAZY_SYMBOL_POINTERS, // sectname __nl_symbol_ptr
|
||||
S_LAZY_SYMBOL_POINTERS, // sectname __la_symbol_ptr
|
||||
S_SYMBOL_STUBS,
|
||||
S_MOD_INIT_FUNC_POINTERS, // sectname __mod_init_func
|
||||
S_MOD_TERM_FUNC_POINTERS,
|
||||
S_COALESCED,
|
||||
S_GB_ZEROFILL,
|
||||
S_INTERPOSING,
|
||||
S_16BYTE_LITERALS,
|
||||
S_DTRACE_DOF
|
||||
};
|
||||
enum { // section flags (high 24 bits)
|
||||
S_ATTR_PURE_INSTRUCTIONS = 0x80000000,
|
||||
S_ATTR_NO_TOC = 0x40000000,
|
||||
S_ATTR_STRIP_STATIC_SYMS = 0x20000000,
|
||||
S_ATTR_NO_DEAD_STRIP = 0x10000000,
|
||||
S_ATTR_LIVE_SUPPORT = 0x08000000,
|
||||
S_ATTR_SELF_MODIFYING_CODE = 0x04000000,
|
||||
S_ATTR_DEBUG = 0x02000000,
|
||||
S_ATTR_SOME_INSTRUCTIONS = 0x00000400,
|
||||
S_ATTR_EXT_RELOC = 0x00000200,
|
||||
S_ATTR_LOC_RELOC = 0x00000100
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
#ifdef WANT_MACH_THREAD_ENUM /*{*/
|
||||
#undef WANT_MACH_THREAD_ENUM
|
||||
enum { // thread flavor
|
||||
PPC_THREAD_STATE = 1,
|
||||
PPC_THREAD_STATE64 = 5,
|
||||
x86_THREAD_STATE32 = 1,
|
||||
x86_THREAD_STATE64 = 4,
|
||||
i386_OLD_THREAD_STATE = -1,
|
||||
ARM_THREAD_STATE = 1
|
||||
};
|
||||
#endif /*}*/
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
+87
-90
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
Jens Medoch
|
||||
<jssg@users.sourceforge.net>
|
||||
@@ -53,7 +53,7 @@ static const
|
||||
#define K0_BS (0x80000000)
|
||||
#define K1_BS (0xa0000000)
|
||||
#define EXE_BS (ih.epc & K0_BS)
|
||||
#define FIX_PSVR (K1_BS - EXE_BS) + (PS_HDR_SIZE - HD_CODE_OFS)
|
||||
#define FIX_PSVR ((K1_BS - EXE_BS) + (PS_HDR_SIZE - HD_CODE_OFS))
|
||||
|
||||
// lui / addiu
|
||||
#define MIPS_HI(a) (((a) >> 16) + (((a) & 0x8000) >> 15))
|
||||
@@ -61,6 +61,7 @@ static const
|
||||
#define MIPS_PC16(a) ((a) >> 2)
|
||||
#define MIPS_PC26(a) (((a) & 0x0fffffff) >> 2)
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// ps1 exe looks like this:
|
||||
// 1. <header> 2048 bytes
|
||||
@@ -81,18 +82,20 @@ PackPs1::PackPs1(InputFile *f) :
|
||||
buildPart2(0), foundBss(0), sa_cnt(0), overlap(0), sz_lunc(0), sz_lcpr(0),
|
||||
pad_code(0), bss_start(0), bss_end(0)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 136);
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_hb_t) == 44);
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_chb_t) == 5);
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_t) == 136)
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_hb_t) == 44)
|
||||
COMPILE_TIME_ASSERT(sizeof(ps1_exe_chb_t) == 5)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_t)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_hb_t)
|
||||
COMPILE_TIME_ASSERT_ALIGNED1(ps1_exe_chb_t)
|
||||
|
||||
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t))
|
||||
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40)
|
||||
|
||||
COMPILE_TIME_ASSERT(PS_HDR_SIZE > sizeof(ps1_exe_t));
|
||||
COMPILE_TIME_ASSERT(SZ_IH_BKUP == 40);
|
||||
#if 0 // 1 || defined(WITH_NRV)
|
||||
COMPILE_TIME_ASSERT(sizeof(nrv_loader) == 14812);
|
||||
COMPILE_TIME_ASSERT(NRV_BOOT_LOADER_CRC32 == 0x0);
|
||||
#endif
|
||||
fdata_size = file_size - PS_HDR_SIZE;
|
||||
ram_size = !opt->ps1_exe.do_8mb ? 0x200000 : 0x800000;
|
||||
ram_size = !opt->ps1_exe.do_8mib ? 0x200000 : 0x800000;
|
||||
}
|
||||
|
||||
const int *PackPs1::getCompressionMethods(int method, int level) const
|
||||
@@ -110,30 +113,6 @@ const int *PackPs1::getFilters() const
|
||||
|
||||
Linker* PackPs1::newLinker() const
|
||||
{
|
||||
class ElfLinkerMipsLE : public ElfLinker
|
||||
{
|
||||
typedef ElfLinker super;
|
||||
|
||||
virtual void relocate1(const Relocation *rel, upx_byte *location,
|
||||
unsigned value, const char *type)
|
||||
{
|
||||
if (strcmp(type, "R_MIPS_HI16") == 0)
|
||||
set_le16(location, get_le16(location) + MIPS_HI(value));
|
||||
else if (strcmp(type, "R_MIPS_LO16") == 0)
|
||||
set_le16(location, get_le16(location) + MIPS_LO(value));
|
||||
else if (strcmp(type, "R_MIPS_PC16") == 0)
|
||||
{
|
||||
value -= rel->section->offset + rel->offset;
|
||||
set_le16(location, get_le16(location) + MIPS_PC16(value));
|
||||
}
|
||||
else if (strcmp(type, "R_MIPS_26") == 0)
|
||||
set_le32(location, get_le32(location) + MIPS_PC26(value));
|
||||
else if (strcmp(type, "R_MIPS_32") == 0)
|
||||
set_le32(location, get_le32(location) + value);
|
||||
else
|
||||
super::relocate1(rel, location, value, type);
|
||||
}
|
||||
};
|
||||
return new ElfLinkerMipsLE;
|
||||
}
|
||||
|
||||
@@ -148,8 +127,8 @@ int PackPs1::readFileHeader()
|
||||
{
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ih, sizeof(ih));
|
||||
if (memcmp(&ih.id, "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id, "EXE X-SP", 8) != 0)
|
||||
if (memcmp(&ih.id[0], "PS-X EXE", 8) != 0 &&
|
||||
memcmp(&ih.id[0], "EXE X-SP", 8) != 0)
|
||||
return 0;
|
||||
if (ih.text != 0 || ih.data != 0)
|
||||
return 0;
|
||||
@@ -173,15 +152,15 @@ bool PackPs1::readBkupHeader()
|
||||
}
|
||||
|
||||
#define INIT_BH_BKUP(p, l) {(p)->id = '1'; (p)->len = l;}
|
||||
#define ADLER16(a) ((a) >> 16 ^ ((a) & 0xffff))
|
||||
#define ADLER16(a) (((a) >> 16) ^ ((a) & 0xffff))
|
||||
|
||||
void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len)
|
||||
{
|
||||
unsigned sz_cbh;
|
||||
unsigned sz_cbh = MemBuffer::getSizeForCompression(SZ_IH_BKUP);
|
||||
|
||||
if (src && dst)
|
||||
{
|
||||
unsigned char *cpr_bh = new unsigned char[MemBuffer::getSizeForCompression(SZ_IH_BKUP)];
|
||||
unsigned char *cpr_bh = new unsigned char[sz_cbh];
|
||||
|
||||
memset(cpr_bh, 0, sizeof(bh));
|
||||
ps1_exe_chb_t * p = (ps1_exe_chb_t * )cpr_bh;
|
||||
@@ -191,7 +170,7 @@ void PackPs1::putBkupHeader(const unsigned char *src, unsigned char *dst, unsign
|
||||
if (r != UPX_E_OK || sz_cbh >= SZ_IH_BKUP)
|
||||
throwInternalError("header compression failed");
|
||||
INIT_BH_BKUP(p, sz_cbh);
|
||||
*len = ALIGN_UP(sz_cbh + sizeof(ps1_exe_chb_t) - 1, 4);
|
||||
*len = ALIGN_UP(sz_cbh + (unsigned) sizeof(ps1_exe_chb_t) - 1, 4u);
|
||||
p->ih_csum = ADLER16(upx_adler32(&ih.epc, SZ_IH_BKUP));
|
||||
memcpy(dst, cpr_bh, SZ_IH_BKUP);
|
||||
delete [] cpr_bh;
|
||||
@@ -215,6 +194,8 @@ bool PackPs1::getBkupHeader(unsigned char *p, unsigned char *dst)
|
||||
unsigned sz_bh = SZ_IH_BKUP;
|
||||
int r = upx_decompress((const unsigned char *)&src->ih_bkup, src->len,
|
||||
unc_bh, &sz_bh, M_NRV2E_8, NULL );
|
||||
if (r == UPX_E_OUT_OF_MEMORY)
|
||||
throwOutOfMemoryException();
|
||||
if (r != UPX_E_OK || sz_bh != SZ_IH_BKUP)
|
||||
throwInternalError("header decompression failed");
|
||||
unsigned ad = upx_adler32(unc_bh, SZ_IH_BKUP);
|
||||
@@ -275,8 +256,9 @@ bool PackPs1::canPack()
|
||||
fi->readx(buf, sizeof(buf));
|
||||
checkAlreadyPacked(buf, sizeof(buf));
|
||||
|
||||
for (unsigned i = 0; i < sizeof(buf); i++)
|
||||
for (size_t i = 0; i < sizeof(buf); i++)
|
||||
if (buf[i] != 0)
|
||||
{
|
||||
if (!opt->force)
|
||||
throwCantPack("unknown data in header (try --force)");
|
||||
else
|
||||
@@ -286,6 +268,7 @@ bool PackPs1::canPack()
|
||||
opt->backup = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!checkFileHeader())
|
||||
throwCantPack("unsupported header flags (try --force)");
|
||||
if (!opt->force && file_size < PS_MIN_SIZE)
|
||||
@@ -300,7 +283,7 @@ bool PackPs1::canPack()
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
int PackPs1::buildLoader(const Filter *)
|
||||
void PackPs1::buildLoader(const Filter *)
|
||||
{
|
||||
const char *method = NULL;
|
||||
|
||||
@@ -322,7 +305,7 @@ int PackPs1::buildLoader(const Filter *)
|
||||
else if (ph.method == M_NRV2E_LE32)
|
||||
method = isCon ? "nrv2e.small,32bit.sub,nrv.done" :
|
||||
"nrv2e.32bit,nrv.done";
|
||||
else if (ph.method == M_LZMA)
|
||||
else if (M_IS_LZMA(ph.method))
|
||||
method = "nrv2b.small,8bit.sub,nrv.done,lzma.prep";
|
||||
else
|
||||
throwInternalError("unknown compression method");
|
||||
@@ -336,14 +319,15 @@ int PackPs1::buildLoader(const Filter *)
|
||||
throwCantPack("packed data overlap (try --force)");
|
||||
}
|
||||
else
|
||||
sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp),4);
|
||||
sa_tmp += overlap = ALIGN_UP((ph.overlap_overhead - sa_tmp), 4u);
|
||||
}
|
||||
|
||||
foundBss = findBssSection();
|
||||
if (isCon || M_IS_LZMA(ph.method))
|
||||
foundBss = findBssSection();
|
||||
|
||||
if (ph.method == M_LZMA && !buildPart2)
|
||||
if (M_IS_LZMA(ph.method) && !buildPart2)
|
||||
{
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
|
||||
addLoader("decompressor.start",
|
||||
isCon ? "LZMA_DEC20" : "LZMA_DEC10", "lzma.init", NULL);
|
||||
addLoader(sa_tmp > (0x10000 << 2) ? "memset.long" : "memset.short",
|
||||
@@ -351,7 +335,7 @@ int PackPs1::buildLoader(const Filter *)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ph.method == M_LZMA && buildPart2)
|
||||
if (M_IS_LZMA(ph.method) && buildPart2)
|
||||
{
|
||||
sz_lcpr = MemBuffer::getSizeForCompression(sz_lunc);
|
||||
unsigned char *cprLoader = new unsigned char[sz_lcpr];
|
||||
@@ -359,20 +343,22 @@ int PackPs1::buildLoader(const Filter *)
|
||||
NULL, M_NRV2B_8, 10, NULL, NULL );
|
||||
if (r != UPX_E_OK || sz_lcpr >= sz_lunc)
|
||||
throwInternalError("loader compression failed");
|
||||
initLoader(nrv_loader, sizeof(nrv_loader),
|
||||
(ph.method != M_LZMA || isCon) ? 0 : 1);
|
||||
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1),
|
||||
isCon || !M_IS_LZMA(ph.method) ? 0 : 1);
|
||||
linker->addSection("lzma.exec", cprLoader, sz_lcpr, 0);
|
||||
delete [] cprLoader;
|
||||
}
|
||||
else
|
||||
initLoader(nrv_loader, sizeof(nrv_loader));
|
||||
initLoader(stub_mipsel_r3000_ps1, sizeof(stub_mipsel_r3000_ps1));
|
||||
|
||||
pad_code = ALIGN_GAP((ph.c_len + (isCon ? sz_lcpr : 0)), 4);
|
||||
linker->addSection("pad.code", &pad_code, pad_code, 0);
|
||||
pad_code = ALIGN_GAP((ph.c_len + (isCon ? sz_lcpr : 0)), 4u);
|
||||
assert(pad_code < 4);
|
||||
static const unsigned char pad_buffer[4] = { 0, 0, 0, 0 };
|
||||
linker->addSection("pad.code", pad_buffer, pad_code, 0);
|
||||
|
||||
if (isCon)
|
||||
{
|
||||
if (ph.method == M_LZMA)
|
||||
if (M_IS_LZMA(ph.method))
|
||||
addLoader(!foundBss ? "con.start" : "bss.con.start",
|
||||
method,
|
||||
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
|
||||
@@ -388,22 +374,24 @@ int PackPs1::buildLoader(const Filter *)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ph.method == M_LZMA)
|
||||
addLoader("cdb.start.lzma", "pad.code", "cdb.entry.lzma", method, "cdb.lzma.cpr",
|
||||
if (M_IS_LZMA(ph.method))
|
||||
addLoader(!foundBss ? "cdb.start.lzma" : "bss.cdb.start.lzma", "pad.code",
|
||||
!foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma",
|
||||
method, "cdb.lzma.cpr",
|
||||
ih.tx_ptr & 0xffff ? "dec.ptr" : "dec.ptr.hi",
|
||||
"lzma.exec", NULL);
|
||||
else
|
||||
{
|
||||
assert(foundBss != true);
|
||||
addLoader("cdb.start", "pad.code", "cdb.entry",
|
||||
ih.tx_ptr & 0xffff ? "cdb.dec.ptr" : "cdb.dec.ptr.hi",
|
||||
method,
|
||||
sa_cnt ? sa_cnt > (0x10000 << 2) ? "memset.long" : "memset.short" : "",
|
||||
!foundBss ? "cdb.exit" : "bss.exit",
|
||||
"pad.code", NULL);
|
||||
"cdb.exit", NULL);
|
||||
}
|
||||
}
|
||||
addLoader("UPX1HEAD", "IDENTSTR", NULL);
|
||||
}
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
#define OPTYPE(x) (((x) >> 13) & 0x7)
|
||||
@@ -411,7 +399,7 @@ int PackPs1::buildLoader(const Filter *)
|
||||
#define REG1(x) (((x) >> 5) & 0x1f)
|
||||
#define REG2(x) ((x) & 0x1f)
|
||||
|
||||
#define MIPS_IMM(a,b) (((a) - (((b) & 0x8000) >> 15) << 16) | (b))
|
||||
#define MIPS_IMM(a,b) ((((a) - (((b) & 0x8000) >> 15)) << 16) | (b))
|
||||
|
||||
// Type
|
||||
#define REGIMM 1
|
||||
@@ -445,7 +433,7 @@ bool PackPs1::findBssSection()
|
||||
reg = REG1(op);
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
bss_nfo *p = (bss_nfo *)&p1[i];
|
||||
bss_nfo *p = (bss_nfo *)(void *)&p1[i];
|
||||
unsigned short op1 = p->op1, op2 = p->op2;
|
||||
|
||||
// check for la (x),bss_start
|
||||
@@ -461,12 +449,12 @@ bool PackPs1::findBssSection()
|
||||
bss_start = MIPS_IMM(p->hi1, p->lo1);
|
||||
bss_end = MIPS_IMM(p->hi2, p->lo2);
|
||||
|
||||
if (0 < ALIGN_DOWN(bss_end - bss_start, 4) )
|
||||
if (0 < ALIGN_DOWN(bss_end - bss_start, 4u))
|
||||
{
|
||||
unsigned wkmem_sz = (ph.method == M_LZMA) ? 32768 : 800;
|
||||
unsigned wkmem_sz = M_IS_LZMA(ph.method) ? 32768 : 800;
|
||||
unsigned end_offs = ih.tx_ptr + fdata_size + overlap;
|
||||
if (bss_end > (end_offs + wkmem_sz))
|
||||
return (isCon || (!isCon && (ph.method == M_LZMA)));
|
||||
return isCon || (!isCon && M_IS_LZMA(ph.method));
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -500,9 +488,9 @@ void PackPs1::pack(OutputFile *fo)
|
||||
while (!(*--p_scan)) { if (sa_cnt++ > (0x10000 << 5) || sa_cnt >= fdata_size - 1024) break; }
|
||||
|
||||
if (sa_cnt > (0x10000 << 2))
|
||||
sa_cnt = ALIGN_DOWN(sa_cnt,32);
|
||||
sa_cnt = ALIGN_DOWN(sa_cnt, 32u);
|
||||
else
|
||||
sa_cnt = ALIGN_DOWN(sa_cnt,4);
|
||||
sa_cnt = ALIGN_DOWN(sa_cnt, 4u);
|
||||
|
||||
// prepare packheader
|
||||
ph.u_len = (fdata_size - sa_cnt);
|
||||
@@ -512,8 +500,8 @@ void PackPs1::pack(OutputFile *fo)
|
||||
// compress (max_match = 65535)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28KB stack
|
||||
compressWithFilters(&ft, sa_cnt, 0, NULL, &cconf);
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, sa_cnt, &cconf);
|
||||
|
||||
if (overlap)
|
||||
{
|
||||
@@ -529,7 +517,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
|
||||
unsigned lzma_init = 0;
|
||||
|
||||
if (ph.method == M_LZMA)
|
||||
if (M_IS_LZMA(ph.method))
|
||||
{
|
||||
sz_lunc = getLoaderSize();
|
||||
|
||||
@@ -538,7 +526,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
linker->defineSymbol("entry", ih.epc);
|
||||
linker->defineSymbol("SC",
|
||||
sa_cnt > (0x10000 << 2) ? sa_cnt >> 5 : sa_cnt >> 2);
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
|
||||
buildPart2 = true;
|
||||
buildLoader(&ft);
|
||||
@@ -558,8 +546,6 @@ void PackPs1::pack(OutputFile *fo)
|
||||
oh.bs_ptr = oh.bs_len = 0;
|
||||
|
||||
const int lsize = getLoaderSize();
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
|
||||
unsigned filelen = ALIGN_UP(ih.tx_len, 4);
|
||||
|
||||
@@ -577,7 +563,9 @@ void PackPs1::pack(OutputFile *fo)
|
||||
}
|
||||
else
|
||||
{
|
||||
d_len = (lsize - h_len) - getLoaderSectionStart((ph.method == M_LZMA) ? "cdb.entry.lzma" : "cdb.entry");
|
||||
const char* entry_lzma = !foundBss ? "cdb.entry.lzma" : "bss.cdb.entry.lzma";
|
||||
|
||||
d_len = (lsize - h_len) - getLoaderSectionStart(M_IS_LZMA(ph.method) ? entry_lzma : "cdb.entry");
|
||||
e_len = (lsize - d_len) - h_len;
|
||||
}
|
||||
|
||||
@@ -585,14 +573,16 @@ void PackPs1::pack(OutputFile *fo)
|
||||
linker->defineSymbol("SC", MIPS_LO(sa_cnt > (0x10000 << 2) ?
|
||||
sa_cnt >> 5 : sa_cnt >> 2));
|
||||
linker->defineSymbol("DECO", decomp_data_start);
|
||||
linker->defineSymbol("ldr_sz", (ph.method == M_LZMA ? sz_lunc + 16 : (d_len-pad_code)));
|
||||
linker->defineSymbol("ldr_sz", M_IS_LZMA(ph.method) ? sz_lunc + 16 : (d_len-pad_code));
|
||||
|
||||
if (foundBss)
|
||||
if (ph.method == M_LZMA)
|
||||
{
|
||||
if (M_IS_LZMA(ph.method))
|
||||
linker->defineSymbol("wrkmem", bss_end - 160 - getDecompressorWrkmemSize()
|
||||
- (sz_lunc + 16));
|
||||
else
|
||||
linker->defineSymbol("wrkmem", bss_end - 16 - (d_len - pad_code));
|
||||
}
|
||||
|
||||
|
||||
const unsigned entry = comp_data_start - e_len;
|
||||
@@ -601,7 +591,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
|
||||
unsigned pad = 0;
|
||||
|
||||
if (!opt->ps1_exe.no_align)
|
||||
if (!opt->ps1_exe.no_align || !isCon)
|
||||
{
|
||||
pad = oh.tx_len;
|
||||
oh.tx_len = ALIGN_UP(oh.tx_len, CD_SEC);
|
||||
@@ -612,7 +602,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
ibuf.clear(0,fdata_size);
|
||||
upx_bytep paddata = ibuf;
|
||||
|
||||
if (ph.method == M_LZMA)
|
||||
if (M_IS_LZMA(ph.method))
|
||||
{
|
||||
linker->defineSymbol("lzma_init_off", lzma_init);
|
||||
linker->defineSymbol("gb_e", linker->getSymbolOffset("gb8_e"));
|
||||
@@ -624,7 +614,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
if (isCon)
|
||||
{
|
||||
linker->defineSymbol("PAD", pad_code);
|
||||
if (ph.method == M_LZMA)
|
||||
if (M_IS_LZMA(ph.method))
|
||||
linker->defineSymbol("DCRT", (entry + getLoaderSectionStart("lzma.exec")));
|
||||
else
|
||||
linker->defineSymbol("DCRT", (entry + (e_len - d_len)));
|
||||
@@ -633,16 +623,23 @@ void PackPs1::pack(OutputFile *fo)
|
||||
{
|
||||
linker->defineSymbol("PSVR", FIX_PSVR);
|
||||
linker->defineSymbol("CPDO", comp_data_start);
|
||||
if (ph.method == M_LZMA)
|
||||
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec")
|
||||
- getLoaderSectionStart("cdb.entry.lzma"));
|
||||
if (M_IS_LZMA(ph.method))
|
||||
{
|
||||
unsigned entry_lzma = getLoaderSectionStart( !foundBss ? "cdb.entry.lzma" :
|
||||
"bss.cdb.entry.lzma");
|
||||
|
||||
linker->defineSymbol("lzma_cpr", getLoaderSectionStart("lzma.exec") - entry_lzma);
|
||||
}
|
||||
}
|
||||
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
//linker->dumpSymbols();
|
||||
MemBuffer loader(lsize);
|
||||
assert(lsize == getLoaderSize());
|
||||
memcpy(loader, getLoader(), lsize);
|
||||
patchPackHeader(loader, lsize);
|
||||
|
||||
if (!isCon && ph.method == M_LZMA && (HD_CODE_OFS + d_len + h_len) > CD_SEC)
|
||||
if (!isCon && M_IS_LZMA(ph.method) && (HD_CODE_OFS + d_len + h_len) > CD_SEC)
|
||||
throwInternalError("lzma --boot-only loader > 2048");
|
||||
|
||||
// ps1_exe_t structure
|
||||
@@ -676,7 +673,7 @@ void PackPs1::pack(OutputFile *fo)
|
||||
printf("%-13s: eof in mem OF : %08X bytes\n", getName(), (unsigned int) oh.tx_ptr + oh.tx_len);
|
||||
unsigned char i = 0;
|
||||
if (isCon) { if (foundBss) i = 1; }
|
||||
else { i = 2; if (ph.method == M_LZMA) { if (!foundBss) i = 3; else i = 4; } }
|
||||
else { i = 2; if (M_IS_LZMA(ph.method)) { if (!foundBss) i = 3; else i = 4; } }
|
||||
const char *loader_method[] = { "con/stack", "con/bss", "cdb", "cdb/stack", "cdb/bss" };
|
||||
char method_name[32+1]; set_method_name(method_name, sizeof(method_name), ph.method, ph.level);
|
||||
printf("%-13s: methods : %s, %s\n", getName(), method_name, loader_method[i]);
|
||||
|
||||
+15
-22
@@ -2,9 +2,9 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 2002-2006 Jens Medoch
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
Copyright (C) 2002-2013 Jens Medoch
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -23,7 +23,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
Jens Medoch
|
||||
<jssg@users.sourceforge.net>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#ifndef __UPX_P_PS1_H
|
||||
#define __UPX_P_PS1_H
|
||||
#define __UPX_P_PS1_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_PS1_EXE; }
|
||||
virtual const char *getName() const { return "ps1/exe"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "mipsel.r3000-ps1"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -59,15 +60,14 @@ protected:
|
||||
virtual void putBkupHeader(const unsigned char *src, unsigned char *dst, unsigned *len);
|
||||
virtual bool getBkupHeader(unsigned char *src, unsigned char * dst);
|
||||
virtual bool readBkupHeader();
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual bool findBssSection();
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct ps1_exe_t
|
||||
{
|
||||
__packed_struct(ps1_exe_t)
|
||||
// ident string
|
||||
char id[8];
|
||||
// is NULL
|
||||
@@ -90,33 +90,26 @@ protected:
|
||||
char origin[60];
|
||||
// backup of the original header (epc - is_len)
|
||||
// id & the upx header ...
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
// for unpack
|
||||
struct ps1_exe_hb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_hb_t)
|
||||
LE32 ih_bkup[10];
|
||||
// plus checksum for the backup
|
||||
LE32 ih_csum;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct ps1_exe_chb_t
|
||||
{
|
||||
__packed_struct(ps1_exe_chb_t)
|
||||
unsigned char id;
|
||||
unsigned char len;
|
||||
LE16 ih_csum;
|
||||
unsigned char ih_bkup;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
typedef struct bss_nfo
|
||||
{
|
||||
__packed_struct(bss_nfo)
|
||||
LE16 hi1, op1, lo1, op2;
|
||||
LE16 hi2, op3, lo2, op4;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
ps1_exe_t ih, oh;
|
||||
ps1_exe_hb_t bh;
|
||||
|
||||
+9
-10
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ void PackSys::patchLoader(OutputFile *fo,
|
||||
{
|
||||
const int e_len = getLoaderSectionStart("SYSCUTPO");
|
||||
const int d_len = lsize - e_len;
|
||||
assert(e_len > 0 && e_len < 256);
|
||||
assert(e_len > 0 && e_len < 128);
|
||||
assert(d_len > 0 && d_len < 256);
|
||||
|
||||
if (ph.u_len + d_len + ph.overlap_overhead > 0xfffe)
|
||||
@@ -85,10 +85,11 @@ void PackSys::patchLoader(OutputFile *fo,
|
||||
linker->defineSymbol("calltrick_calls", calls);
|
||||
linker->defineSymbol("copy_source", ph.c_len + lsize - 1);
|
||||
linker->defineSymbol("copy_destination", copy_to);
|
||||
linker->defineSymbol("neg_e_len", 0 - e_len);
|
||||
linker->defineSymbol("NRV2B160", ph.u_len + ph.overlap_overhead + 1);
|
||||
linker->defineSymbol("original_strategy", get_le16(ibuf + 6));
|
||||
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
loader = getLoader();
|
||||
|
||||
patchPackHeader(loader,e_len);
|
||||
@@ -99,9 +100,9 @@ void PackSys::patchLoader(OutputFile *fo,
|
||||
}
|
||||
|
||||
|
||||
int PackSys::buildLoader(const Filter *ft)
|
||||
void PackSys::buildLoader(const Filter *ft)
|
||||
{
|
||||
initLoader(nrv2b_loader,sizeof(nrv2b_loader));
|
||||
initLoader(stub_i086_dos16_sys, sizeof(stub_i086_dos16_sys));
|
||||
addLoader("SYSMAIN1",
|
||||
opt->cpu == opt->CPU_8086 ? "SYSI0861" : "SYSI2861",
|
||||
"SYSMAIN2",
|
||||
@@ -122,8 +123,6 @@ int PackSys::buildLoader(const Filter *ft)
|
||||
"SYSJUMP1",
|
||||
NULL
|
||||
);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+8
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_SYS_H
|
||||
#define __UPX_P_SYS_H
|
||||
#define __UPX_P_SYS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_DOS_SYS; }
|
||||
virtual const char *getName() const { return "dos/sys"; }
|
||||
//virtual const char *getFullName(const options_t *o) const { return o && o->cpu == o->CPU_8086 ? "i086-dos16.sys" : "i286-dos16.sys"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i086-dos16.sys"; }
|
||||
|
||||
virtual bool canPack();
|
||||
|
||||
@@ -49,7 +51,7 @@ protected:
|
||||
virtual unsigned getCallTrickOffset() const { return 0; }
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void patchLoader(OutputFile *fo, upx_byte *, int, unsigned);
|
||||
};
|
||||
|
||||
|
||||
+25
-30
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ static const
|
||||
|
||||
PackTmt::PackTmt(InputFile *f) : super(f)
|
||||
{
|
||||
bele = &N_BELE_RTP::le_policy;
|
||||
COMPILE_TIME_ASSERT(sizeof(tmt_header_t) == 44);
|
||||
}
|
||||
|
||||
@@ -58,18 +59,20 @@ const int *PackTmt::getCompressionMethods(int method, int level) const
|
||||
const int *PackTmt::getFilters() const
|
||||
{
|
||||
static const int filters[] = {
|
||||
0x26, 0x24, 0x11, 0x14, 0x13, 0x16, 0x25, 0x12, 0x15,
|
||||
-1 };
|
||||
0x26, 0x24, 0x49, 0x46, 0x16, 0x13, 0x14, 0x11,
|
||||
FT_ULTRA_BRUTE, 0x25, 0x15, 0x12,
|
||||
FT_END };
|
||||
return filters;
|
||||
}
|
||||
|
||||
|
||||
unsigned PackTmt::findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range,
|
||||
unsigned upper_limit) const
|
||||
{
|
||||
// make sure the decompressor will be paragraph aligned
|
||||
unsigned o = super::findOverlapOverhead(buf, range, upper_limit);
|
||||
unsigned o = super::findOverlapOverhead(buf, tbuf, range, upper_limit);
|
||||
o = ((o + 0x20) &~ 0xf) - (ph.u_len & 0xf);
|
||||
return o;
|
||||
}
|
||||
@@ -81,11 +84,13 @@ Linker* PackTmt::newLinker() const
|
||||
}
|
||||
|
||||
|
||||
int PackTmt::buildLoader(const Filter *ft)
|
||||
void PackTmt::buildLoader(const Filter *ft)
|
||||
{
|
||||
// prepare loader
|
||||
initLoader(nrv_loader,sizeof(nrv_loader));
|
||||
initLoader(stub_i386_dos32_tmt, sizeof(stub_i386_dos32_tmt));
|
||||
addLoader("IDENTSTR,TMTMAIN1",
|
||||
ph.first_offset_found == 1 ? "TMTMAIN1A" : "",
|
||||
"TMTMAIN1B",
|
||||
ft->id ? "TMTCALT1" : "",
|
||||
"TMTMAIN2,UPX1HEAD,TMTCUTPO",
|
||||
NULL);
|
||||
@@ -105,8 +110,6 @@ int PackTmt::buildLoader(const Filter *ft)
|
||||
"RELOC32J,TMTJUMP1",
|
||||
NULL
|
||||
);
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +172,7 @@ int PackTmt::readFileHeader()
|
||||
|
||||
fi->seek(adam_offset,SEEK_SET);
|
||||
fi->readx(&ih,sizeof(ih));
|
||||
// FIXME: should add some checks for the values in `ih'
|
||||
// FIXME: should add some checks for the values in 'ih'
|
||||
|
||||
return UPX_F_TMT_ADAM;
|
||||
#undef H4
|
||||
@@ -185,19 +188,6 @@ bool PackTmt::canPack()
|
||||
}
|
||||
|
||||
|
||||
static bool defineFilterSymbols(Linker *linker, const Filter *ft)
|
||||
{
|
||||
if (ft->id == 0)
|
||||
return false;
|
||||
assert(ft->calls > 0);
|
||||
|
||||
linker->defineSymbol("filter_cto", ft->cto);
|
||||
linker->defineSymbol("filter_length",
|
||||
(ft->id & 0xf) % 3 == 0 ? ft->calls :
|
||||
ft->lastcall - ft->calls * 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
@@ -250,7 +240,10 @@ void PackTmt::pack(OutputFile *fo)
|
||||
Filter ft(ph.level);
|
||||
ft.buf_len = usize;
|
||||
// compress
|
||||
compressWithFilters(&ft, 512);
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
// limit stack size needed for runtime decompression
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
const unsigned lsize = getLoaderSize();
|
||||
const unsigned s_point = getLoaderSection("TMTMAIN1");
|
||||
@@ -260,17 +253,17 @@ void PackTmt::pack(OutputFile *fo)
|
||||
|
||||
// patch loader
|
||||
linker->defineSymbol("original_entry", ih.entry);
|
||||
defineFilterSymbols(linker, &ft);
|
||||
defineDecompressorSymbols();
|
||||
defineFilterSymbols(&ft);
|
||||
|
||||
linker->defineSymbol("bytes_to_copy", ph.c_len + d_len);
|
||||
linker->defineSymbol("copy_dest", ph.u_len + ph.overlap_overhead + d_len - 1);
|
||||
linker->defineSymbol("copy_dest", 0u - (ph.u_len + ph.overlap_overhead + d_len - 1));
|
||||
linker->defineSymbol("copy_source", ph.c_len + lsize - 1);
|
||||
//fprintf(stderr,"\nelen=%x dlen=%x copy_len=%x copy_to=%x oo=%x jmp_pos=%x ulen=%x c_len=%x \n\n",
|
||||
// e_len,d_len,copy_len,copy_to,ph.overlap_overhead,jmp_pos,ph.u_len,ph.c_len);
|
||||
|
||||
linker->defineSymbol("TMTCUTPO", ph.u_len + ph.overlap_overhead);
|
||||
linker->relocate();
|
||||
relocateLoader();
|
||||
|
||||
MemBuffer loader(lsize);
|
||||
memcpy(loader,getLoader(),lsize);
|
||||
@@ -334,7 +327,9 @@ void PackTmt::unpack(OutputFile *fo)
|
||||
{
|
||||
Filter ft(ph.level);
|
||||
ft.init(ph.filter, 0);
|
||||
ft.cto = (unsigned char) (ph.version < 11 ? (get_le32(obuf+ph.u_len-12) >> 24) : ph.filter_cto);
|
||||
ft.cto = (unsigned char) ph.filter_cto;
|
||||
if (ph.version < 11)
|
||||
ft.cto = (unsigned char) (get_le32(obuf+ph.u_len-12) >> 24);
|
||||
ft.unfilter(obuf, ptr_diff(relocs, obuf));
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,13 +21,13 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_TMT_H
|
||||
#define __UPX_P_TMT_H
|
||||
#define __UPX_P_TMT_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_TMT_ADAM; }
|
||||
virtual const char *getName() const { return "tmt/adam"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-dos32.tmt.adam"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -55,9 +56,10 @@ protected:
|
||||
virtual int readFileHeader();
|
||||
|
||||
virtual unsigned findOverlapOverhead(const upx_bytep buf,
|
||||
const upx_bytep tbuf,
|
||||
unsigned range = 0,
|
||||
unsigned upper_limit = ~0u) const;
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
|
||||
unsigned adam_offset;
|
||||
|
||||
+337
-265
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,7 +22,7 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
static const
|
||||
#include "stub/m68k-atari.tos.h"
|
||||
|
||||
// #define TESTING
|
||||
//#define TESTING 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -49,6 +49,7 @@ static const
|
||||
PackTos::PackTos(InputFile *f) :
|
||||
super(f)
|
||||
{
|
||||
bele = &N_BELE_RTP::be_policy;
|
||||
COMPILE_TIME_ASSERT(FH_SIZE == 28);
|
||||
}
|
||||
|
||||
@@ -72,42 +73,171 @@ Linker* PackTos::newLinker() const
|
||||
}
|
||||
|
||||
|
||||
int PackTos::buildLoader(const Filter *ft)
|
||||
void PackTos::LinkerSymbols::LoopInfo::init(unsigned count_, bool allow_dbra)
|
||||
{
|
||||
count = value = count_;
|
||||
if (count == 0)
|
||||
mode = LOOP_NONE;
|
||||
else if (count <= 65536 && allow_dbra)
|
||||
{
|
||||
mode = LOOP_DBRA;
|
||||
value -= 1;
|
||||
value &= 0xffff;
|
||||
}
|
||||
else if (count <= 65536)
|
||||
{
|
||||
mode = LOOP_SUBQ_W;
|
||||
value &= 0xffff;
|
||||
}
|
||||
else
|
||||
mode = LOOP_SUBQ_L;
|
||||
}
|
||||
|
||||
|
||||
unsigned PackTos::getDecomprOffset(int method, int small) const
|
||||
{
|
||||
UNUSED(small);
|
||||
if (M_IS_NRV2B(method))
|
||||
return 2; // FIXME: do not hardcode this value
|
||||
else if (M_IS_NRV2D(method))
|
||||
return 2; // FIXME: do not hardcode this value
|
||||
else if (M_IS_NRV2E(method))
|
||||
return 2; // FIXME: do not hardcode this value
|
||||
else if (M_IS_LZMA(method))
|
||||
return linker->getSectionSize("__mulsi3");
|
||||
else
|
||||
throwBadLoader();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void PackTos::buildLoader(const Filter *ft)
|
||||
{
|
||||
assert(ft->id == 0);
|
||||
|
||||
const unsigned char *p = NULL;
|
||||
size_t l = 0;
|
||||
initLoader(stub_m68k_atari_tos, sizeof(stub_m68k_atari_tos));
|
||||
//linker->dumpSymbols();
|
||||
|
||||
//
|
||||
// part 1a
|
||||
//
|
||||
|
||||
addLoader("entry");
|
||||
|
||||
if (symbols.up21_a6 <= 32767)
|
||||
addLoader("set_up21_a6.w");
|
||||
else if (symbols.up21_d4 <= 32767)
|
||||
addLoader("set_up21_d4.w");
|
||||
else
|
||||
addLoader("set_up21_d4.l");
|
||||
|
||||
assert(symbols.loop1.count || symbols.loop2.count);
|
||||
if (symbols.loop1.count)
|
||||
{
|
||||
if (symbols.loop1.value <= 127)
|
||||
addLoader("loop1_set_count.b");
|
||||
else if (symbols.loop1.value <= 65535)
|
||||
addLoader("loop1_set_count.w");
|
||||
else
|
||||
addLoader("loop1_set_count.l");
|
||||
addLoader("loop1_label");
|
||||
addLoader(opt->small ? "loop1.small" : "loop1.fast");
|
||||
if (symbols.loop1.mode == symbols.LOOP_SUBQ_L)
|
||||
addLoader("loop1_subql");
|
||||
else if (symbols.loop1.mode == symbols.LOOP_SUBQ_W)
|
||||
addLoader("loop1_subqw");
|
||||
else if (symbols.loop1.mode == symbols.LOOP_DBRA)
|
||||
addLoader("loop1_dbra");
|
||||
else
|
||||
throwBadLoader();
|
||||
}
|
||||
if (symbols.loop2.count)
|
||||
{
|
||||
assert(symbols.loop2.mode == symbols.LOOP_DBRA);
|
||||
addLoader(opt->small ? "loop2.small" : "loop2.fast");
|
||||
}
|
||||
|
||||
addLoader("copy_to_stack");
|
||||
|
||||
if (M_IS_NRV2B(ph.method))
|
||||
addLoader("nrv2b.init");
|
||||
else if (M_IS_NRV2D(ph.method))
|
||||
addLoader("nrv2d.init");
|
||||
else if (M_IS_NRV2E(ph.method))
|
||||
addLoader("nrv2e.init");
|
||||
else if (M_IS_LZMA(ph.method))
|
||||
addLoader("lzma.init");
|
||||
else
|
||||
throwBadLoader();
|
||||
|
||||
symbols.up31_d4 = symbols.up31_base_d4 + getDecomprOffset(ph.method, opt->small);
|
||||
symbols.up31_a6 = symbols.up31_base_a6 + getDecomprOffset(ph.method, opt->small);
|
||||
if (symbols.up31_a6 <= 32767)
|
||||
addLoader("jmp_decompressor_a6.w");
|
||||
else if (symbols.up31_d4 <= 32767)
|
||||
addLoader("jmp_decompressor_d4.w");
|
||||
else if (symbols.up31_a6 <= 65534)
|
||||
addLoader("jmp_decompressor_a6.w2");
|
||||
else
|
||||
addLoader("jmp_decompressor_d4.l");
|
||||
|
||||
//
|
||||
// part 1b
|
||||
//
|
||||
|
||||
addLoader("code_on_stack");
|
||||
|
||||
addLoader("clear_dirty_bss");
|
||||
addLoader("loop3_label");
|
||||
addLoader(opt->small ? "loop3.small" : "loop3.fast");
|
||||
if (symbols.loop3.mode == symbols.LOOP_SUBQ_L)
|
||||
addLoader("loop3_subql");
|
||||
else if (symbols.loop3.mode == symbols.LOOP_SUBQ_W)
|
||||
addLoader("loop3_subqw");
|
||||
else if (symbols.loop3.mode == symbols.LOOP_DBRA)
|
||||
addLoader("loop3_dbra");
|
||||
else
|
||||
throwBadLoader();
|
||||
|
||||
addLoader("flush_cache");
|
||||
addLoader("restore_stack");
|
||||
#if 0
|
||||
addLoader("clear_dirty_stack");
|
||||
#endif
|
||||
addLoader("start_program");
|
||||
|
||||
addLoader("IDENTSTR,+40D,UPX1HEAD,CUTPOINT");
|
||||
|
||||
//
|
||||
// part 2
|
||||
//
|
||||
|
||||
p = nrv_loader;
|
||||
if (M_IS_NRV2B(ph.method)) {
|
||||
// p = opt->small ? nrv2b_loader_small : nrv2b_loader;
|
||||
// l = opt->small ? sizeof(nrv2b_loader_small) : sizeof(nrv2b_loader);
|
||||
addLoader(opt->small ? "nrv2b_8.small" : "nrv2b_8.fast");
|
||||
} else if (M_IS_NRV2D(ph.method)) {
|
||||
addLoader(opt->small ? "nrv2d_8.small" : "nrv2d_8.fast");
|
||||
} else if (M_IS_NRV2E(ph.method)) {
|
||||
addLoader(opt->small ? "nrv2e_8.small" : "nrv2e_8.fast");
|
||||
} else if (M_IS_LZMA(ph.method)) {
|
||||
addLoader("__mulsi3");
|
||||
addLoader(opt->small ? "lzma.small" : "lzma.fast");
|
||||
addLoader("lzma.finish");
|
||||
}
|
||||
if (M_IS_NRV2D(ph.method)) {
|
||||
// p = opt->small ? nrv2d_loader_small : nrv2d_loader;
|
||||
// l = opt->small ? sizeof(nrv2d_loader_small) : sizeof(nrv2d_loader);
|
||||
}
|
||||
if (M_IS_NRV2E(ph.method)) {
|
||||
// p = opt->small ? nrv2e_loader_small : nrv2e_loader;
|
||||
// l = opt->small ? sizeof(nrv2e_loader_small) : sizeof(nrv2e_loader);
|
||||
}
|
||||
initLoader(p, l);
|
||||
else
|
||||
throwBadLoader();
|
||||
|
||||
addLoader("tos0",
|
||||
true ? "subql_1d0" : "subqw_1d0",
|
||||
"s_bneloop0",
|
||||
true ? "subql_1d6" : "subqw_1d6",
|
||||
"s_bneloop3",
|
||||
"IDENTSTR,+40,UPX1HEAD",
|
||||
"CUTPOINT",
|
||||
true ? "reloc" : "",
|
||||
"jmpastack",
|
||||
NULL
|
||||
);
|
||||
if (symbols.need_reloc)
|
||||
addLoader("reloc");
|
||||
|
||||
freezeLoader();
|
||||
return getLoaderSize();
|
||||
assert(symbols.loop3.count);
|
||||
if (symbols.loop3.value <= 127)
|
||||
addLoader("loop3_set_count.b");
|
||||
else if (symbols.loop3.value <= 65535)
|
||||
addLoader("loop3_set_count.w");
|
||||
else
|
||||
addLoader("loop3_set_count.l");
|
||||
|
||||
addLoader("jmp_stack");
|
||||
}
|
||||
|
||||
|
||||
@@ -177,142 +307,25 @@ bool PackTos::checkFileHeader()
|
||||
if ((f & F_PROTMODE) != F_PROT_P)
|
||||
{
|
||||
if (opt->force < 1)
|
||||
throwCantPack("no private memory protection; use option `-f' to force packing");
|
||||
throwCantPack("no private memory protection; use option '-f' to force packing");
|
||||
}
|
||||
if (f & F_SHTEXT)
|
||||
{
|
||||
if (opt->force < 1)
|
||||
throwCantPack("shared text segment; use option `-f' to force packing");
|
||||
throwCantPack("shared text segment; use option '-f' to force packing");
|
||||
}
|
||||
#if 0
|
||||
// fh_reserved seems to be unused
|
||||
if (ih.fh_reserved != 0)
|
||||
{
|
||||
if (opt->force < 1)
|
||||
throwCantPack("reserved header field set; use option `-f' to force packing");
|
||||
throwCantPack("reserved header field set; use option '-f' to force packing");
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// some 68000 opcodes for patching
|
||||
**************************************************************************/
|
||||
|
||||
#if 0
|
||||
enum m68k_reg_t {
|
||||
REG_D0, REG_D1, REG_D2, REG_D3, REG_D4, REG_D5, REG_D6, REG_D7,
|
||||
REG_A0, REG_A1, REG_A2, REG_A3, REG_A4, REG_A5, REG_A6, REG_A7
|
||||
};
|
||||
|
||||
static unsigned OP_DBRA(int d_reg)
|
||||
{
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
return 0x51c8 | (d_reg & 7);
|
||||
}
|
||||
|
||||
static unsigned OP_JMP(int a_reg)
|
||||
{
|
||||
// jmp (a0)
|
||||
assert(a_reg >= REG_A0 && a_reg <= REG_A7);
|
||||
return 0x4ed0 | (a_reg & 7);
|
||||
}
|
||||
|
||||
static unsigned OP_MOVEI_L(int d_reg)
|
||||
{
|
||||
// movei.l #XXXXXXXX,d0
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
return 0x203c | ((d_reg & 7) << 9);
|
||||
}
|
||||
|
||||
static unsigned OP_MOVEQ(int value, int d_reg)
|
||||
{
|
||||
// moveq.l #0,d0
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
assert(value >= -128 && value <= 127);
|
||||
return 0x7000 | ((d_reg & 7) << 9) | (value & 0xff);
|
||||
}
|
||||
|
||||
static unsigned OP_SUBQ_L(int value, int d_reg)
|
||||
{
|
||||
// subq.l #X,d0
|
||||
assert(value >= 1 && value <= 8);
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
return 0x5180 | ((value & 7) << 9) | (d_reg & 7);
|
||||
}
|
||||
|
||||
static unsigned OP_SUBQ_W(int value, int d_reg)
|
||||
{
|
||||
// subq.w #X,d0
|
||||
assert(value >= 1 && value <= 8);
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
return 0x5140 | ((value & 7) << 9) | (d_reg & 7);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
unsigned PackTos::patch_d_subq(void *b, int blen,
|
||||
int d_reg, unsigned d_value,
|
||||
const char *subq_marker)
|
||||
{
|
||||
// patch a "subq.l #1,d0" or "subq.w #1,d0".
|
||||
// also convert into "dbra" if possible
|
||||
assert(d_reg >= REG_D0 && d_reg <= REG_D7);
|
||||
assert((int)d_value > 0);
|
||||
|
||||
int boff = find_be16(b, blen, get_be16(subq_marker));
|
||||
if (boff < 0)
|
||||
throwBadLoader();
|
||||
|
||||
upx_byte *p = (upx_byte *)b + boff;
|
||||
if (p[2] == 0x66) // bne.b XXX
|
||||
checkPatch(b, blen, boff, 4);
|
||||
else
|
||||
checkPatch(b, blen, boff, 2);
|
||||
|
||||
if (d_value > 65536)
|
||||
{
|
||||
set_be16(p, OP_SUBQ_L(1, d_reg)); // subq.l #1,d0
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p[2] == 0x66) // bne.b XXX
|
||||
{
|
||||
set_be16(p, OP_DBRA(d_reg)); // dbra d0,XXX
|
||||
// adjust and extend branch from 8 to 16 bits
|
||||
int branch = (signed char) p[3];
|
||||
set_be16(p+2, branch+2);
|
||||
// adjust d0
|
||||
d_value -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_be16(p, OP_SUBQ_W(1, d_reg)); // subq.w #1,d0
|
||||
}
|
||||
d_value &= 0xffff;
|
||||
}
|
||||
return d_value;
|
||||
}
|
||||
|
||||
|
||||
unsigned PackTos::patch_d_loop(void *b, int blen,
|
||||
int d_reg, unsigned d_value,
|
||||
const char *d_marker, const char *subq_marker)
|
||||
{
|
||||
d_value = patch_d_subq(b, blen, d_reg, d_value, subq_marker);
|
||||
|
||||
int boff = find_be32(b, blen, get_be32(d_marker));
|
||||
checkPatch(b, blen, boff, 4);
|
||||
upx_byte *p = (upx_byte *)b + boff;
|
||||
assert(get_be16(p - 2) == OP_MOVEI_L(d_reg)); // move.l #XXXXXXXX,d0
|
||||
set_be32(p, d_value);
|
||||
return d_value;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
// relocs
|
||||
**************************************************************************/
|
||||
@@ -366,18 +379,6 @@ static int check_relocs(const upx_byte *relocs, unsigned rsize, unsigned isize,
|
||||
|
||||
bool PackTos::canPack()
|
||||
{
|
||||
#if 0 // debug
|
||||
# define p(x) printf("%-30s 0x%04x\n", #x, x)
|
||||
p(OP_DBRA(REG_D0));
|
||||
p(OP_MOVEI_L(REG_D0));
|
||||
p(OP_MOVEQ(-1, REG_D0));
|
||||
p(OP_MOVEQ(1, REG_D2));
|
||||
p(OP_MOVEQ(1, REG_D3));
|
||||
p(OP_SUBQ_W(1, REG_D0));
|
||||
p(OP_SUBQ_L(1, REG_D0));
|
||||
# undef p
|
||||
#endif
|
||||
|
||||
if (!readFileHeader())
|
||||
return false;
|
||||
|
||||
@@ -409,7 +410,6 @@ void PackTos::fileInfo()
|
||||
|
||||
void PackTos::pack(OutputFile *fo)
|
||||
{
|
||||
throwInternalError("atari/tos is currenty broken; this will get fixed in UPX 2.91");
|
||||
unsigned t;
|
||||
unsigned nrelocs = 0;
|
||||
unsigned relocsize = 0;
|
||||
@@ -421,6 +421,15 @@ void PackTos::pack(OutputFile *fo)
|
||||
const unsigned i_bss = ih.fh_bss;
|
||||
|
||||
symbols.reset();
|
||||
symbols.need_reloc = false;
|
||||
// prepare symbols for buildLoader() - worst case
|
||||
symbols.loop1.init(65536 + 1);
|
||||
symbols.loop2.init((160 - 1) / 4);
|
||||
symbols.loop3.init(65536 + 1);
|
||||
symbols.up21_d4 = 65536 + 1;
|
||||
symbols.up21_a6 = 65536 + 1;
|
||||
symbols.up31_base_d4 = 65536 + 1;
|
||||
symbols.up31_base_a6 = 65536 + 1;
|
||||
|
||||
// read file
|
||||
const unsigned isize = file_size - i_sym;
|
||||
@@ -430,12 +439,14 @@ void PackTos::pack(OutputFile *fo)
|
||||
t = i_text + i_data;
|
||||
fi->readx(ibuf,t);
|
||||
// skip symbols
|
||||
if (i_sym && opt->exact)
|
||||
throwCantPackExact();
|
||||
fi->seek(i_sym,SEEK_CUR);
|
||||
// read relocations + overlay
|
||||
overlay = file_size - (FH_SIZE + i_text + i_data + i_sym);
|
||||
fi->readx(ibuf+t,overlay);
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("text: %d, data: %d, sym: %d, bss: %d, flags=0x%x\n",
|
||||
i_text, i_data, i_sym, i_bss, (int)ih.fh_flag);
|
||||
printf("xx1 reloc: %d, overlay: %d, fixup: %d\n", relocsize, overlay, overlay >= 4 ? (int)get_be32(ibuf+t) : -1);
|
||||
@@ -443,7 +454,6 @@ void PackTos::pack(OutputFile *fo)
|
||||
|
||||
// Check relocs (see load_and_reloc() in freemint/sys/memory.c).
|
||||
// Must work around TOS bugs and lots of broken programs.
|
||||
int r = 0;
|
||||
if (overlay < 4)
|
||||
{
|
||||
// Bug workaround: Whatever this is, silently keep it in
|
||||
@@ -459,15 +469,17 @@ void PackTos::pack(OutputFile *fo)
|
||||
}
|
||||
else if (ih.fh_reloc != 0)
|
||||
relocsize = 0;
|
||||
else
|
||||
r = check_relocs(ibuf+t, overlay, t, &nrelocs, &relocsize, &overlay);
|
||||
else {
|
||||
int r = check_relocs(ibuf+t, overlay, t, &nrelocs, &relocsize, &overlay);
|
||||
if (r != 0)
|
||||
throwCantPack("bad relocation table");
|
||||
symbols.need_reloc = true;
|
||||
}
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("xx2: %d relocs: %d, overlay: %d, t: %d\n", nrelocs, relocsize, overlay, t);
|
||||
#endif
|
||||
|
||||
if (r != 0)
|
||||
throwCantPack("bad relocation table");
|
||||
checkOverlay(overlay);
|
||||
|
||||
// Append original fileheader.
|
||||
@@ -475,7 +487,7 @@ void PackTos::pack(OutputFile *fo)
|
||||
ih.fh_sym = 0; // we stripped all symbols
|
||||
memcpy(ibuf+t, &ih, FH_SIZE);
|
||||
t += FH_SIZE;
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("xx3 reloc: %d, overlay: %d, t: %d\n", relocsize, overlay, t);
|
||||
#endif
|
||||
assert(t <= isize);
|
||||
@@ -485,8 +497,8 @@ void PackTos::pack(OutputFile *fo)
|
||||
// After compression this will become the first part of the
|
||||
// data segement. The second part will be the decompressor.
|
||||
|
||||
// alloc buffer (2048 is for decompressor and the various alignments)
|
||||
obuf.allocForCompression(t, 2048);
|
||||
// alloc buffer (4096 is for decompressor and the various alignments)
|
||||
obuf.allocForCompression(t, 4096);
|
||||
|
||||
// prepare packheader
|
||||
ph.u_len = t;
|
||||
@@ -495,102 +507,163 @@ void PackTos::pack(OutputFile *fo)
|
||||
// compress (max_match = 65535)
|
||||
upx_compress_config_t cconf; cconf.reset();
|
||||
cconf.conf_ucl.max_match = 65535;
|
||||
compressWithFilters(&ft, 512, 0, NULL, &cconf);
|
||||
cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack
|
||||
compressWithFilters(&ft, 512, &cconf);
|
||||
|
||||
// get loader
|
||||
const unsigned lsize = getLoaderSize();
|
||||
const unsigned e_len = getLoaderSectionStart("CUTPOINT");
|
||||
const unsigned d_len = lsize - e_len;
|
||||
const unsigned decomp_offset = linker->getSymbolOffset("decompr_start") - e_len;
|
||||
assert(decomp_offset != 0xdeaddead);
|
||||
assert((e_len & 3) == 0 && (d_len & 1) == 0);
|
||||
//
|
||||
// multipass buildLoader()
|
||||
//
|
||||
|
||||
// The decompressed data will now get placed at this offset:
|
||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||
// save initial loader
|
||||
const unsigned initial_lsize = getLoaderSize();
|
||||
unsigned last_lsize = initial_lsize;
|
||||
MemBuffer last_loader(last_lsize);
|
||||
memcpy(last_loader, getLoader(), last_lsize);
|
||||
|
||||
// compute addresses
|
||||
unsigned o_text, o_data, o_bss;
|
||||
o_text = e_len;
|
||||
o_data = ph.c_len;
|
||||
o_bss = i_bss;
|
||||
|
||||
// word align len of compressed data
|
||||
while (o_data & 1)
|
||||
unsigned e_len, d_len, d_off;
|
||||
for (;;)
|
||||
{
|
||||
obuf[o_data++] = 0;
|
||||
offset++;
|
||||
}
|
||||
// The decompressed data will now get placed at this offset:
|
||||
unsigned offset = (ph.u_len + ph.overlap_overhead) - ph.c_len;
|
||||
|
||||
// append decompressor (part 2 of loader)
|
||||
const unsigned d_off = o_data;
|
||||
o_data += d_len;
|
||||
// get loader
|
||||
const unsigned lsize = getLoaderSize();
|
||||
e_len = getLoaderSectionStart("CUTPOINT");
|
||||
d_len = lsize - e_len;
|
||||
assert((e_len & 3) == 0 && (d_len & 1) == 0);
|
||||
|
||||
// dword align the len of the final data segment
|
||||
while (o_data & 3)
|
||||
{
|
||||
obuf[o_data++] = 0;
|
||||
offset++;
|
||||
}
|
||||
// dword align offset
|
||||
while (offset & 3)
|
||||
offset++;
|
||||
// compute section sizes
|
||||
o_text = e_len;
|
||||
o_data = ph.c_len;
|
||||
o_bss = i_bss;
|
||||
|
||||
// new bss
|
||||
if (i_text + i_data + i_bss > o_text + o_data + o_bss)
|
||||
o_bss = (i_text + i_data + i_bss) - (o_text + o_data);
|
||||
|
||||
// dirty bss
|
||||
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
|
||||
//printf("real dirty_bss: %d\n", dirty_bss);
|
||||
// dword align (or 16 - for speedup when clearing the dirty bss)
|
||||
const unsigned dirty_bss_align = opt->small ? 4 : 16;
|
||||
while (dirty_bss & (dirty_bss_align - 1))
|
||||
dirty_bss++;
|
||||
// adjust bss, assert room for some stack
|
||||
if (dirty_bss + 512 > o_bss)
|
||||
o_bss = dirty_bss + 512;
|
||||
|
||||
// dword align the len of the final bss segment
|
||||
while (o_bss & 3)
|
||||
o_bss++;
|
||||
|
||||
// patch "subq.l #1,d6" or "subq.w #1,d6" - see "up41" below
|
||||
const unsigned dirty_bss_d6 = dirty_bss / dirty_bss_align;
|
||||
// FIXME patch_d_subq(loader, o_text, REG_D6, dirty_bss / dirty_bss_align, "u4");
|
||||
linker->defineSymbol("up31", d_off + offset + decomp_offset);
|
||||
if (opt->small)
|
||||
; // patch_d_loop(loader, o_text, REG_D0, o_data/4, "up22", "u1");
|
||||
else
|
||||
{
|
||||
if (o_data <= 160)
|
||||
throwNotCompressible();
|
||||
unsigned loop1 = o_data / 160;
|
||||
unsigned loop2 = o_data % 160;
|
||||
if (loop2 == 0)
|
||||
// word align len of compressed data
|
||||
while (o_data & 1)
|
||||
{
|
||||
loop1--;
|
||||
loop2 = 160;
|
||||
obuf[o_data++] = 0;
|
||||
offset++;
|
||||
}
|
||||
linker->defineSymbol("copy_remain", loop2 / 4 - 1);
|
||||
//patch_be16(loader, o_text, "u2", OP_MOVEQ(loop2/4-1, REG_D0)); // moveq.l #X,d0
|
||||
//patch_d_loop(loader, o_text, REG_D0, loop1, "up22", "u1");
|
||||
|
||||
// append decompressor (part 2 of loader)
|
||||
d_off = o_data;
|
||||
////memcpy(obuf + d_off, getLoader() + e_len, d_len); // must be done after relocation
|
||||
o_data += d_len;
|
||||
|
||||
// dword align the len of the final data segment
|
||||
while (o_data & 3)
|
||||
{
|
||||
obuf[o_data++] = 0;
|
||||
offset++;
|
||||
}
|
||||
// dword align offset
|
||||
while (offset & 3)
|
||||
offset++;
|
||||
|
||||
// new bss
|
||||
if (i_text + i_data + i_bss > o_text + o_data + o_bss)
|
||||
o_bss = (i_text + i_data + i_bss) - (o_text + o_data);
|
||||
|
||||
// dirty bss
|
||||
unsigned dirty_bss = (o_data + offset) - (i_text + i_data);
|
||||
//printf("real dirty_bss: %d\n", dirty_bss);
|
||||
// dword align (or 16 - for speedup when clearing the dirty bss)
|
||||
const unsigned dirty_bss_align = opt->small ? 4 : 16;
|
||||
while (dirty_bss & (dirty_bss_align - 1))
|
||||
dirty_bss++;
|
||||
// adjust bss, assert room for some stack
|
||||
unsigned stack = 512 + getDecompressorWrkmemSize();
|
||||
if (dirty_bss + stack > o_bss)
|
||||
o_bss = dirty_bss + stack;
|
||||
|
||||
// dword align the len of the final bss segment
|
||||
while (o_bss & 3)
|
||||
o_bss++;
|
||||
|
||||
// update symbols for buildLoader()
|
||||
if (opt->small)
|
||||
{
|
||||
symbols.loop1.init(o_data / 4);
|
||||
symbols.loop2.init(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbols.loop1.init(o_data / 160);
|
||||
symbols.loop2.init((o_data % 160) / 4);
|
||||
}
|
||||
symbols.loop3.init(dirty_bss / dirty_bss_align);
|
||||
|
||||
symbols.up21_d4 = o_data + offset;
|
||||
symbols.up31_base_d4 = d_off + offset;
|
||||
symbols.up21_a6 = symbols.up21_d4 - (i_text + i_data);
|
||||
symbols.up31_base_a6 = symbols.up31_base_d4 - (i_text + i_data);
|
||||
assert((int)symbols.up21_a6 > 0);
|
||||
assert((int)symbols.up31_base_a6 > 0);
|
||||
|
||||
const unsigned c = linker->getSymbolOffset("code_on_stack");
|
||||
unsigned d;
|
||||
d = linker->getSymbolOffset("flush_cache_rts") - c;
|
||||
symbols.flush_cache_rts_offset = d;
|
||||
d = linker->getSymbolOffset("clear_dirty_stack_loop") - c;
|
||||
symbols.clear_dirty_stack_len = (d + 3) / 4 + 32 - 1;
|
||||
d = linker->getSymbolOffset("code_on_stack_end") - c;
|
||||
symbols.copy_to_stack_len = d / 2 - 1;
|
||||
|
||||
// now re-build loader
|
||||
buildLoader(&ft);
|
||||
unsigned new_lsize = getLoaderSize();
|
||||
//printf("buildLoader %d %d\n", new_lsize, initial_lsize);
|
||||
assert(new_lsize <= initial_lsize);
|
||||
if (new_lsize == last_lsize && memcmp(getLoader(), last_loader, last_lsize) == 0)
|
||||
break;
|
||||
last_lsize = new_lsize;
|
||||
memcpy(last_loader, getLoader(), last_lsize);
|
||||
}
|
||||
linker->defineSymbol("up22", opt->small ? o_data / 4 : (o_data - 1) / 160);
|
||||
linker->defineSymbol("up21", o_data + offset);
|
||||
linker->defineSymbol("up13", i_bss); // p_blen
|
||||
linker->defineSymbol("up12", i_data); // p_dlen
|
||||
linker->defineSymbol("up11", i_text); // p_tlen
|
||||
|
||||
const unsigned clear_size = linker->getSymbolOffset("clear_bss_end") -
|
||||
linker->getSymbolOffset("clear_bss");
|
||||
linker->defineSymbol("copy_to_stack_len", clear_size / 2 - 1);
|
||||
linker->defineSymbol("clear_bss_size_p4", clear_size + 4);
|
||||
//
|
||||
// define symbols and reloc
|
||||
//
|
||||
|
||||
// patch decompressor
|
||||
//upx_byte *p = obuf + d_off;
|
||||
// patch "moveq.l #1,d5" or "jmp (ASTACK)"
|
||||
//patch_be16(p, d_len, "u3", (nrelocs > 0) ? OP_MOVEQ(1, REG_D5) : OP_JMP(REG_A7));
|
||||
linker->defineSymbol("up41", dirty_bss_d6);
|
||||
defineDecompressorSymbols();
|
||||
|
||||
linker->defineSymbol("loop1_count", symbols.loop1.value);
|
||||
linker->defineSymbol("loop2_count", symbols.loop2.value);
|
||||
linker->defineSymbol("loop3_count", symbols.loop3.value);
|
||||
|
||||
linker->defineSymbol("orig_p_tlen", i_text);
|
||||
linker->defineSymbol("orig_p_dlen", i_data);
|
||||
linker->defineSymbol("orig_p_blen", i_bss);
|
||||
|
||||
if (symbols.up21_a6 <= 32767)
|
||||
linker->defineSymbol("up21_a6", symbols.up21_a6);
|
||||
else
|
||||
linker->defineSymbol("up21_d4", symbols.up21_d4);
|
||||
|
||||
if (symbols.up31_a6 <= 32767)
|
||||
linker->defineSymbol("up31_a6", symbols.up31_a6);
|
||||
else if (symbols.up31_d4 <= 32767)
|
||||
linker->defineSymbol("up31_d4", symbols.up31_d4);
|
||||
else if (symbols.up31_a6 <= 65534)
|
||||
linker->defineSymbol("up31_a6", symbols.up31_a6 - 32767);
|
||||
else
|
||||
linker->defineSymbol("up31_d4", symbols.up31_d4);
|
||||
#if 0
|
||||
printf("relocsize = %d\n", relocsize);
|
||||
printf("upx21(d4) = %d\n", symbols.up21_d4);
|
||||
printf("upx21(a6) = %d\n", symbols.up21_a6);
|
||||
printf("upx31(d4) = %d\n", symbols.up31_d4);
|
||||
printf("upx31(a6) = %d\n", symbols.up31_a6);
|
||||
#endif
|
||||
|
||||
linker->defineSymbol("flush_cache_rts_offset", symbols.flush_cache_rts_offset);
|
||||
linker->defineSymbol("copy_to_stack_len", symbols.copy_to_stack_len);
|
||||
linker->defineSymbol("clear_dirty_stack_len", symbols.clear_dirty_stack_len);
|
||||
|
||||
relocateLoader();
|
||||
|
||||
//
|
||||
// write
|
||||
//
|
||||
|
||||
// set new file_hdr
|
||||
memcpy(&oh, &ih, FH_SIZE);
|
||||
@@ -613,19 +686,17 @@ void PackTos::pack(OutputFile *fo)
|
||||
// add an empty relocation fixup to workaround a bug in some TOS versions
|
||||
oh.fh_reloc = 0;
|
||||
|
||||
#if 0 || defined(TESTING)
|
||||
#if 0 || (TESTING)
|
||||
printf("old text: %6d, data: %6d, bss: %6d, reloc: %d, overlay: %d\n",
|
||||
i_text, i_data, i_bss, relocsize, overlay);
|
||||
printf("new text: %6d, data: %6d, bss: %6d, dirty_bss: %d, flag=0x%x\n",
|
||||
o_text, o_data, o_bss, dirty_bss, (int)oh.fh_flag);
|
||||
printf("new text: %6d, data: %6d, bss: %6d, flag=0x%x\n",
|
||||
o_text, o_data, o_bss, (int)oh.fh_flag);
|
||||
linker->dumpSymbols();
|
||||
#endif
|
||||
|
||||
linker->relocate();
|
||||
// prepare loader
|
||||
MemBuffer loader(o_text);
|
||||
memcpy(loader, getLoader(), o_text);
|
||||
memcpy(obuf+d_off, getLoader() + e_len, d_len);
|
||||
|
||||
patchPackHeader(loader, o_text);
|
||||
|
||||
// write new file header, loader and compressed file
|
||||
@@ -633,10 +704,11 @@ void PackTos::pack(OutputFile *fo)
|
||||
fo->write(loader, o_text); // entry
|
||||
if (opt->debug.dump_stub_loader)
|
||||
OutputFile::dump(opt->debug.dump_stub_loader, loader, o_text);
|
||||
memcpy(obuf + d_off, getLoader() + e_len, d_len); // copy decompressor
|
||||
fo->write(obuf, o_data); // compressed + decompressor
|
||||
|
||||
// write empty relocation fixup
|
||||
fo->write("\x00\x00\x00\x00",4);
|
||||
fo->write("\x00\x00\x00\x00", 4);
|
||||
|
||||
// verify
|
||||
verifyOverlappingDecompression();
|
||||
|
||||
+29
-22
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_TOS_H
|
||||
#define __UPX_P_TOS_H
|
||||
#define __UPX_P_TOS_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_ATARI_TOS; }
|
||||
virtual const char *getName() const { return "atari/tos"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "m68k-atari.tos"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
@@ -55,13 +56,13 @@ public:
|
||||
|
||||
protected:
|
||||
virtual Linker* newLinker() const;
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
unsigned getDecomprOffset(int method, int small) const;
|
||||
|
||||
virtual int readFileHeader();
|
||||
virtual bool checkFileHeader();
|
||||
|
||||
struct tos_header_t
|
||||
{
|
||||
__packed_struct(tos_header_t)
|
||||
BE16 fh_magic;
|
||||
BE32 fh_text;
|
||||
BE32 fh_data;
|
||||
@@ -70,32 +71,38 @@ protected:
|
||||
BE32 fh_reserved;
|
||||
BE32 fh_flag;
|
||||
BE16 fh_reloc;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
tos_header_t ih, oh;
|
||||
|
||||
// symbols for buildLoader()
|
||||
struct LinkerSymbols
|
||||
{
|
||||
enum { LOOP_UNKNOWN, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
|
||||
// before linker->relocate()
|
||||
unsigned loop1_count; int loop1_mode;
|
||||
unsigned loop2_count; int loop2_mode;
|
||||
unsigned loop3_count; int loop3_mode;
|
||||
// after linker->relocate()
|
||||
unsigned copy_to_stack_len;
|
||||
enum { LOOP_NONE, LOOP_SUBQ_L, LOOP_SUBQ_W, LOOP_DBRA };
|
||||
struct LoopInfo {
|
||||
unsigned mode; unsigned count; unsigned value;
|
||||
void init(unsigned count, bool allow_dbra=true);
|
||||
};
|
||||
// buildLoader() input
|
||||
bool need_reloc;
|
||||
LoopInfo loop1;
|
||||
LoopInfo loop2;
|
||||
LoopInfo loop3;
|
||||
unsigned up21_d4;
|
||||
unsigned up21_a6;
|
||||
unsigned up31_base_d4;
|
||||
unsigned up31_base_a6;
|
||||
// buildLoader() output
|
||||
unsigned up31_d4;
|
||||
unsigned up31_a6;
|
||||
// currently not used by buildLoader()
|
||||
unsigned flush_cache_rts_offset;
|
||||
unsigned clear_bss_size_p4;
|
||||
unsigned clear_dirty_stack_len;
|
||||
// FIXME: up11 etc.
|
||||
unsigned copy_to_stack_len;
|
||||
|
||||
void reset() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
LinkerSymbols symbols;
|
||||
|
||||
protected:
|
||||
unsigned patch_d_subq(void *l, int llen, int, unsigned, const char*);
|
||||
unsigned patch_d_loop(void *l, int llen, int, unsigned, const char*, const char*);
|
||||
};
|
||||
|
||||
|
||||
|
||||
+68
-52
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,8 +21,8 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ bool PackUnix::canPack()
|
||||
#if defined(__unix__)
|
||||
// must be executable by owner
|
||||
if ((fi->st.st_mode & S_IXUSR) == 0)
|
||||
throwCantPack("file not executable; try `chmod +x'");
|
||||
throwCantPack("file not executable; try 'chmod +x'");
|
||||
#endif
|
||||
if (file_size < 4096)
|
||||
throwCantPack("file is too small");
|
||||
@@ -125,12 +125,12 @@ int PackUnix::getStrategy(Filter &/*ft*/)
|
||||
// Called just before reading and compressing each block.
|
||||
// Might want to adjust blocksize, etc.
|
||||
|
||||
// If user specified the filter, then use it (-2==strategy).
|
||||
// Else try the first two filters, and pick the better (2==strategy).
|
||||
// If user specified the filter, then use it (-2==filter_strategy).
|
||||
// Else try the first two filters, and pick the better (2==filter_strategy).
|
||||
return (opt->no_filter ? -3 : ((opt->filter > 0) ? -2 : 2));
|
||||
}
|
||||
|
||||
void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
int PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
{
|
||||
// compress blocks
|
||||
unsigned total_in = 0;
|
||||
@@ -142,6 +142,7 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// ui_total_passes = 0;
|
||||
|
||||
unsigned remaining = file_size;
|
||||
unsigned n_block = 0;
|
||||
while (remaining > 0)
|
||||
{
|
||||
// FIXME: disable filters if we have more than one block.
|
||||
@@ -151,9 +152,9 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// which assumes it has free choice on each call [block].
|
||||
// And if the choices aren't the same on each block,
|
||||
// then un-filtering will give incorrect results.
|
||||
int strategy = getStrategy(ft);
|
||||
int filter_strategy = getStrategy(ft);
|
||||
if (file_size > (off_t)blocksize)
|
||||
strategy = -3; // no filters
|
||||
filter_strategy = -3; // no filters
|
||||
|
||||
int l = fi->readx(ibuf, UPX_MIN(blocksize, remaining));
|
||||
remaining -= l;
|
||||
@@ -170,11 +171,14 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// that is, AFTER filtering. We want BEFORE filtering,
|
||||
// so that decompression checks the end-to-end checksum.
|
||||
unsigned const end_u_adler = upx_adler32(ibuf, ph.u_len, ph.u_adler);
|
||||
compressWithFilters(&ft, OVERHEAD, strategy);
|
||||
compressWithFilters(&ft, OVERHEAD, NULL_cconf, filter_strategy,
|
||||
!!n_block++); // check compression ratio only on first block
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
const upx_bytep tbuf = NULL;
|
||||
if (ft.id == 0) tbuf = ibuf;
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
@@ -189,8 +193,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
// write block header
|
||||
b_info blk_info;
|
||||
memset(&blk_info, 0, sizeof(blk_info));
|
||||
set_native32(&blk_info.sz_unc, ph.u_len);
|
||||
set_native32(&blk_info.sz_cpr, ph.c_len);
|
||||
set_te32(&blk_info.sz_unc, ph.u_len);
|
||||
set_te32(&blk_info.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
blk_info.b_method = (unsigned char) ph.method;
|
||||
blk_info.b_ftid = (unsigned char) ph.filter;
|
||||
@@ -220,6 +224,8 @@ void PackUnix::pack2(OutputFile *fo, Filter &ft)
|
||||
if ((off_t)total_in != file_size) {
|
||||
throwEOFException();
|
||||
}
|
||||
|
||||
return 1; // default: write end-of-compression bhdr next
|
||||
}
|
||||
|
||||
void
|
||||
@@ -229,11 +235,11 @@ PackUnix::patchLoaderChecksum()
|
||||
l_info *const lp = &linfo;
|
||||
// checksum for loader; also some PackHeader info
|
||||
lp->l_magic = UPX_MAGIC_LE32; // LE32 always
|
||||
lp->l_lsize = (unsigned short) lsize;
|
||||
set_te16(&lp->l_lsize, (unsigned short) lsize);
|
||||
lp->l_version = (unsigned char) ph.version;
|
||||
lp->l_format = (unsigned char) ph.format;
|
||||
// INFO: lp->l_checksum is currently unused
|
||||
lp->l_checksum = upx_adler32(ptr, lsize);
|
||||
set_te32(&lp->l_checksum, upx_adler32(ptr, lsize));
|
||||
}
|
||||
|
||||
void PackUnix::pack3(OutputFile *fo, Filter &/*ft*/)
|
||||
@@ -250,7 +256,7 @@ void PackUnix::pack4(OutputFile *fo, Filter &)
|
||||
writePackHeader(fo);
|
||||
|
||||
unsigned tmp;
|
||||
set_native32(&tmp, overlay_offset);
|
||||
set_te32(&tmp, overlay_offset);
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
@@ -276,17 +282,18 @@ void PackUnix::pack(OutputFile *fo)
|
||||
pack1(fo, ft); // generate Elf header, etc.
|
||||
|
||||
p_info hbuf;
|
||||
set_native32(&hbuf.p_progid, progid);
|
||||
set_native32(&hbuf.p_filesize, file_size);
|
||||
set_native32(&hbuf.p_blocksize, blocksize);
|
||||
set_te32(&hbuf.p_progid, progid);
|
||||
set_te32(&hbuf.p_filesize, file_size);
|
||||
set_te32(&hbuf.p_blocksize, blocksize);
|
||||
fo->write(&hbuf, sizeof(hbuf));
|
||||
|
||||
pack2(fo, ft); // append the compressed body
|
||||
|
||||
// write block end marker (uncompressed size 0)
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
|
||||
fo->write(&hdr, sizeof(hdr));
|
||||
// append the compressed body
|
||||
if (pack2(fo, ft)) {
|
||||
// write block end marker (uncompressed size 0)
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
set_le32(&hdr.sz_cpr, UPX_MAGIC_LE32);
|
||||
fo->write(&hdr, sizeof(hdr));
|
||||
}
|
||||
|
||||
pack3(fo, ft); // append loader
|
||||
|
||||
@@ -318,7 +325,7 @@ void PackUnix::packExtent(
|
||||
}
|
||||
fi->seek(x.offset, SEEK_SET);
|
||||
for (off_t rest = x.size; 0 != rest; ) {
|
||||
int const strategy = getStrategy(*ft);
|
||||
int const filter_strategy = getStrategy(*ft);
|
||||
int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize));
|
||||
if (l == 0) {
|
||||
break;
|
||||
@@ -345,17 +352,18 @@ void PackUnix::packExtent(
|
||||
ft->id = 0;
|
||||
ft->cto = 0;
|
||||
|
||||
compressWithFilters(ft, OVERHEAD, strategy,
|
||||
NULL, NULL, 0, 0, // those 4 args are the defaults
|
||||
hdr_ibuf, hdr_u_len);
|
||||
compressWithFilters(ft, OVERHEAD, NULL_cconf, filter_strategy,
|
||||
0, 0, 0, hdr_ibuf, hdr_u_len);
|
||||
}
|
||||
else {
|
||||
(void) compress(ibuf, obuf); // ignore return value
|
||||
(void) compress(ibuf, ph.u_len, obuf); // ignore return value
|
||||
}
|
||||
|
||||
if (ph.c_len < ph.u_len) {
|
||||
const upx_bytep tbuf = NULL;
|
||||
if (ft == NULL || ft->id == 0) tbuf = ibuf;
|
||||
ph.overlap_overhead = OVERHEAD;
|
||||
if (!testOverlappingDecompression(obuf, ph.overlap_overhead)) {
|
||||
if (!testOverlappingDecompression(obuf, tbuf, ph.overlap_overhead)) {
|
||||
// not in-place compressible
|
||||
ph.c_len = ph.u_len;
|
||||
}
|
||||
@@ -386,8 +394,8 @@ void PackUnix::packExtent(
|
||||
ph.c_adler = upx_adler32(obuf, ph.c_len, ph.saved_c_adler);
|
||||
end_u_adler = ph.u_adler;
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, hdr_u_len);
|
||||
set_native32(&tmp.sz_cpr, hdr_c_len);
|
||||
set_te32(&tmp.sz_unc, hdr_u_len);
|
||||
set_te32(&tmp.sz_cpr, hdr_c_len);
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
@@ -397,8 +405,8 @@ void PackUnix::packExtent(
|
||||
hdr_u_len = 0; // compress hdr one time only
|
||||
}
|
||||
memset(&tmp, 0, sizeof(tmp));
|
||||
set_native32(&tmp.sz_unc, ph.u_len);
|
||||
set_native32(&tmp.sz_cpr, ph.c_len);
|
||||
set_te32(&tmp.sz_unc, ph.u_len);
|
||||
set_te32(&tmp.sz_cpr, ph.c_len);
|
||||
if (ph.c_len < ph.u_len) {
|
||||
tmp.b_method = (unsigned char) ph.method;
|
||||
if (ft) {
|
||||
@@ -409,6 +417,9 @@ void PackUnix::packExtent(
|
||||
fo->write(&tmp, sizeof(tmp));
|
||||
b_len += sizeof(b_info);
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
// write compressed data
|
||||
if (ph.c_len < ph.u_len) {
|
||||
fo->write(obuf, ph.c_len);
|
||||
@@ -419,9 +430,6 @@ void PackUnix::packExtent(
|
||||
fo->write(ibuf, ph.u_len);
|
||||
}
|
||||
|
||||
if (ft) {
|
||||
ph.u_adler = end_u_adler;
|
||||
}
|
||||
total_in += ph.u_len;
|
||||
total_out += ph.c_len;
|
||||
}
|
||||
@@ -436,8 +444,8 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
b_info hdr; memset(&hdr, 0, sizeof(hdr));
|
||||
while (wanted) {
|
||||
fi->readx(&hdr, szb_info);
|
||||
int const sz_unc = ph.u_len = get_native32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_native32(&hdr.sz_cpr);
|
||||
int const sz_unc = ph.u_len = get_te32(&hdr.sz_unc);
|
||||
int const sz_cpr = ph.c_len = get_te32(&hdr.sz_cpr);
|
||||
ph.filter_cto = hdr.b_cto8;
|
||||
|
||||
if (sz_unc == 0) { // must never happen while 0!=wanted
|
||||
@@ -495,18 +503,26 @@ void PackUnix::unpackExtent(unsigned wanted, OutputFile *fo,
|
||||
|
||||
int PackUnix::canUnpack()
|
||||
{
|
||||
upx_byte buf[128];
|
||||
const int bufsize = sizeof(buf);
|
||||
int const small = 32 + sizeof(overlay_offset);
|
||||
// Allow zero-filled last page, for Mac OS X code signing.
|
||||
int bufsize = 2*4096 + 2*small +1;
|
||||
if (bufsize > fi->st_size())
|
||||
bufsize = fi->st_size();
|
||||
MemBuffer buf(bufsize);
|
||||
|
||||
fi->seek(-bufsize, SEEK_END);
|
||||
fi->readx(buf, bufsize);
|
||||
if (!getPackHeader(buf, bufsize))
|
||||
int i = bufsize;
|
||||
while (i > small && 0 == buf[--i]) { }
|
||||
i -= small;
|
||||
// allow incompressible extents
|
||||
if (i < 0 || !getPackHeader(buf + i, bufsize - i, true))
|
||||
return false;
|
||||
|
||||
int l = ph.buf_offset + ph.getPackHeaderSize();
|
||||
if (l < 0 || l + 4 > bufsize)
|
||||
throwCantUnpack("file corrupted");
|
||||
overlay_offset = get_native32(buf+l);
|
||||
overlay_offset = get_te32(buf + i + l);
|
||||
if ((off_t)overlay_offset >= file_size)
|
||||
throwCantUnpack("file corrupted");
|
||||
|
||||
@@ -528,15 +544,15 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
Elf32_Ehdr ehdr;
|
||||
fi->seek(0, SEEK_SET);
|
||||
fi->readx(&ehdr, sizeof(ehdr));
|
||||
unsigned const e_entry = get_native32(&ehdr.e_entry);
|
||||
unsigned const e_entry = get_te32(&ehdr.e_entry);
|
||||
if (e_entry < 0x401180) { /* old style, 8-byte b_info */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
else {
|
||||
Elf32_Phdr phdr;
|
||||
fi->seek(get_native32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->seek(get_te32(&ehdr.e_phoff), SEEK_SET);
|
||||
fi->readx(&phdr, sizeof(phdr));
|
||||
unsigned const p_vaddr = get_native32(&phdr.p_vaddr);
|
||||
unsigned const p_vaddr = get_te32(&phdr.p_vaddr);
|
||||
if (0x80==(e_entry - p_vaddr)) { /* 1.22 old style */
|
||||
szb_info = 2*sizeof(unsigned);
|
||||
}
|
||||
@@ -555,8 +571,8 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
{
|
||||
p_info hbuf;
|
||||
fi->readx(&hbuf, sizeof(hbuf));
|
||||
orig_file_size = get_native32(&hbuf.p_filesize);
|
||||
blocksize = get_native32(&hbuf.p_blocksize);
|
||||
orig_file_size = get_te32(&hbuf.p_filesize);
|
||||
blocksize = get_te32(&hbuf.p_blocksize);
|
||||
|
||||
if (file_size > (off_t)orig_file_size || blocksize > orig_file_size)
|
||||
throwCantUnpack("file header corrupted");
|
||||
@@ -580,8 +596,8 @@ void PackUnix::unpack(OutputFile *fo)
|
||||
unsigned sz_unc, sz_cpr;
|
||||
|
||||
fi->readx(&bhdr, szb_info);
|
||||
ph.u_len = sz_unc = get_native32(&bhdr.sz_unc);
|
||||
ph.c_len = sz_cpr = get_native32(&bhdr.sz_cpr);
|
||||
ph.u_len = sz_unc = get_te32(&bhdr.sz_unc);
|
||||
ph.c_len = sz_cpr = get_te32(&bhdr.sz_cpr);
|
||||
|
||||
if (sz_unc == 0) // uncompressed size 0 -> EOF
|
||||
{
|
||||
|
||||
+32
-61
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -22,12 +22,12 @@
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<mfx@users.sourceforge.net> <ml1050@users.sourceforge.net>
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_UNIX_H
|
||||
#define __UPX_P_UNIX_H
|
||||
#define __UPX_P_UNIX_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
protected:
|
||||
// called by the generic pack()
|
||||
virtual void pack1(OutputFile *, Filter &); // generate executable header
|
||||
virtual void pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual int pack2(OutputFile *, Filter &); // append compressed data
|
||||
virtual void pack3(OutputFile *, Filter &); // append loader
|
||||
virtual void pack4(OutputFile *, Filter &); // append PackHeader
|
||||
|
||||
@@ -64,15 +64,6 @@ protected:
|
||||
|
||||
virtual void writePackHeader(OutputFile *fo);
|
||||
|
||||
// in order too share as much code as possible we introduce
|
||||
// an endian abstraction here
|
||||
virtual acc_uint64l_t get_native64(const void *) const = 0;
|
||||
virtual unsigned get_native32(const void *) const = 0;
|
||||
virtual unsigned get_native16(const void *) const = 0;
|
||||
virtual void set_native64(void *, acc_uint64l_t) const = 0;
|
||||
virtual void set_native32(void *, unsigned) const = 0;
|
||||
virtual void set_native16(void *, unsigned) const = 0;
|
||||
|
||||
virtual bool checkCompressionRatio(unsigned, unsigned) const;
|
||||
|
||||
protected:
|
||||
@@ -101,30 +92,28 @@ protected:
|
||||
unsigned b_len; // total length of b_info blocks
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
unsigned sz_unc; // uncompressed_size
|
||||
unsigned sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
unsigned l_checksum;
|
||||
unsigned l_magic;
|
||||
unsigned short l_lsize;
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
unsigned p_progid;
|
||||
unsigned p_filesize;
|
||||
unsigned p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct l_info linfo;
|
||||
|
||||
@@ -141,40 +130,31 @@ class PackUnixBe32 : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixBe32(InputFile *f) : super(f) { }
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_be64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_be32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_be16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_be64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_be32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_be16(b, v); }
|
||||
PackUnixBe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::be_policy; }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
BE32 sz_unc; // uncompressed_size
|
||||
BE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
BE32 l_checksum;
|
||||
BE32 l_magic;
|
||||
BE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
BE32 p_progid;
|
||||
BE32 p_filesize;
|
||||
BE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
@@ -182,40 +162,31 @@ class PackUnixLe32 : public PackUnix
|
||||
{
|
||||
typedef PackUnix super;
|
||||
protected:
|
||||
PackUnixLe32(InputFile *f) : super(f) { }
|
||||
virtual acc_uint64l_t get_native64(const void *b) const { return get_le64(b); }
|
||||
virtual unsigned get_native32(const void *b) const { return get_le32(b); }
|
||||
virtual unsigned get_native16(const void *b) const { return get_le16(b); }
|
||||
virtual void set_native64(void *b, acc_uint64l_t v) const { set_le64(b, v); }
|
||||
virtual void set_native32(void *b, unsigned v) const { set_le32(b, v); }
|
||||
virtual void set_native16(void *b, unsigned v) const { set_le16(b, v); }
|
||||
PackUnixLe32(InputFile *f) : super(f) { bele = &N_BELE_RTP::le_policy; }
|
||||
|
||||
// must agree with stub/linux.hh
|
||||
struct b_info { // 12-byte header before each compressed block
|
||||
__packed_struct(b_info) // 12-byte header before each compressed block
|
||||
LE32 sz_unc; // uncompressed_size
|
||||
LE32 sz_cpr; // compressed_size
|
||||
unsigned char b_method; // compression algorithm
|
||||
unsigned char b_ftid; // filter id
|
||||
unsigned char b_cto8; // filter parameter
|
||||
unsigned char b_unused;
|
||||
}
|
||||
__attribute_packed;
|
||||
struct l_info { // 12-byte trailer in header for loader
|
||||
__packed_struct_end()
|
||||
|
||||
__packed_struct(l_info) // 12-byte trailer in header for loader
|
||||
LE32 l_checksum;
|
||||
LE32 l_magic;
|
||||
LE16 l_lsize;
|
||||
unsigned char l_version;
|
||||
unsigned char l_format;
|
||||
}
|
||||
__attribute_packed;
|
||||
__packed_struct_end()
|
||||
|
||||
struct p_info { // 12-byte packed program header
|
||||
__packed_struct(p_info) // 12-byte packed program header
|
||||
LE32 p_progid;
|
||||
LE32 p_filesize;
|
||||
LE32 p_blocksize;
|
||||
}
|
||||
__attribute_packed;
|
||||
|
||||
__packed_struct_end()
|
||||
};
|
||||
|
||||
|
||||
@@ -235,7 +206,7 @@ public:
|
||||
virtual bool canPack();
|
||||
|
||||
protected:
|
||||
virtual const upx_byte *getLoader() const;
|
||||
virtual upx_byte *getLoader() const;
|
||||
virtual int getLoaderSize() const;
|
||||
|
||||
virtual void patchLoader();
|
||||
|
||||
+1067
-261
File diff suppressed because it is too large
Load Diff
+175
-28
@@ -2,8 +2,8 @@
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2006 Laszlo Molnar
|
||||
Copyright (C) 1996-2013 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2013 Laszlo Molnar
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
@@ -21,52 +21,199 @@
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
markus@oberhumer.com ml1050@users.sourceforge.net
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_P_VMLINX_H
|
||||
#define __UPX_P_VMLINX_H
|
||||
#define __UPX_P_VMLINX_H 1
|
||||
|
||||
#include "p_elf.h"
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// vmlinx/i386 (bare binary Linux kernel image)
|
||||
**************************************************************************/
|
||||
|
||||
class PackVmlinuxI386 : public Packer
|
||||
template <class TElfClass>
|
||||
class PackVmlinuxBase : public Packer
|
||||
{
|
||||
typedef Packer super;
|
||||
protected:
|
||||
typedef TElfClass ElfClass;
|
||||
typedef typename ElfClass::BeLePolicy BeLePolicy;
|
||||
typedef typename ElfClass::ElfITypes ElfITypes;
|
||||
// integral types
|
||||
typedef typename ElfClass::TE16 TE16;
|
||||
typedef typename ElfClass::TE32 TE32;
|
||||
typedef typename ElfClass::TE64 TE64;
|
||||
typedef typename ElfITypes::Addr Addr;
|
||||
// ELF types
|
||||
typedef typename ElfClass::Ehdr Ehdr;
|
||||
typedef typename ElfClass::Shdr Shdr;
|
||||
typedef typename ElfClass::Phdr Phdr;
|
||||
typedef typename ElfClass::Dyn Dyn;
|
||||
typedef typename ElfClass::Sym Sym;
|
||||
|
||||
public:
|
||||
PackVmlinuxI386(InputFile *f);
|
||||
virtual ~PackVmlinuxI386();
|
||||
PackVmlinuxBase(InputFile *, unsigned, unsigned, unsigned, char const *);
|
||||
virtual ~PackVmlinuxBase();
|
||||
virtual int getVersion() const { return 13; }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_i386; }
|
||||
virtual const char *getName() const { return "vmlinux/386"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual void unpack(OutputFile *fo);
|
||||
|
||||
virtual bool canPack();
|
||||
virtual int canUnpack();
|
||||
|
||||
protected:
|
||||
virtual int buildLoader(const Filter *ft);
|
||||
virtual Linker* newLinker() const;
|
||||
// virtual const upx_byte *getLoader() const;
|
||||
// virtual int getLoaderSize() const;
|
||||
unsigned int const my_e_machine;
|
||||
unsigned char const my_elfclass;
|
||||
unsigned char const my_elfdata;
|
||||
char const *const my_boot_label;
|
||||
|
||||
int n_ptload;
|
||||
unsigned sz_ptload;
|
||||
Elf_LE32_Phdr *phdri; // from input file
|
||||
Elf_LE32_Shdr *shdri; // from input file
|
||||
Elf_LE32_Shdr *p_text;
|
||||
Elf_LE32_Shdr *p_note0;
|
||||
Elf_LE32_Shdr *p_note1;
|
||||
Elf_LE32_Ehdr ehdri; // from input file
|
||||
unsigned paddr_min;
|
||||
Phdr *phdri; // from input file
|
||||
Shdr *shdri; // from input file
|
||||
char *shstrtab; // from input file
|
||||
Shdr *p_text;
|
||||
Shdr *p_note0;
|
||||
Shdr *p_note1;
|
||||
Ehdr ehdri; // from input file
|
||||
|
||||
virtual Shdr const *getElfSections();
|
||||
virtual int getStrategy(Filter &/*ft*/);
|
||||
virtual bool is_valid_e_entry(Addr) = 0;
|
||||
virtual bool has_valid_vmlinux_head() = 0;
|
||||
virtual bool canPack();
|
||||
virtual void pack(OutputFile *fo);
|
||||
virtual int canUnpack(); // bool, except -1: format known, but not packed
|
||||
virtual void unpack(OutputFile *fo);
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
) = 0;
|
||||
static int __acc_cdecl_qsort compare_Phdr(void const *aa, void const *bb);
|
||||
};
|
||||
|
||||
|
||||
class PackVmlinuxI386 : public PackVmlinuxBase<ElfClass_LE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_LE32> super;
|
||||
public:
|
||||
PackVmlinuxI386(InputFile *f) : super(f, Ehdr::EM_386,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2LSB, "startup_32") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_i386; }
|
||||
virtual const char *getName() const { return "vmlinux/386"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "i386-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
class PackVmlinuxARMEL : public PackVmlinuxBase<ElfClass_LE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_LE32> super;
|
||||
public:
|
||||
PackVmlinuxARMEL(InputFile *f) : super(f, Ehdr::EM_ARM,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2LSB, "decompress_kernel") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_ARMEL; }
|
||||
virtual const char *getName() const { return "vmlinux/armel"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "arm-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
class PackVmlinuxARMEB : public PackVmlinuxBase<ElfClass_BE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_BE32> super;
|
||||
public:
|
||||
PackVmlinuxARMEB(InputFile *f) : super(f, Ehdr::EM_ARM,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "decompress_kernel") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_ARMEB; }
|
||||
virtual const char *getName() const { return "vmlinux/armeb"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "armeb-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
class PackVmlinuxPPC32 : public PackVmlinuxBase<ElfClass_BE32>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_BE32> super;
|
||||
public:
|
||||
PackVmlinuxPPC32(InputFile *f) : super(f, Ehdr::EM_PPC,
|
||||
Ehdr::ELFCLASS32, Ehdr::ELFDATA2MSB, "_vmlinux_start") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_PPC32; }
|
||||
virtual const char *getName() const { return "vmlinux/ppc32"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "powerpc-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
class PackVmlinuxAMD64 : public PackVmlinuxBase<ElfClass_LE64>
|
||||
{
|
||||
typedef PackVmlinuxBase<ElfClass_LE64> super;
|
||||
public:
|
||||
PackVmlinuxAMD64(InputFile *f) : super(f, Ehdr::EM_X86_64,
|
||||
Ehdr::ELFCLASS64, Ehdr::ELFDATA2LSB, "startup_32") { }
|
||||
virtual int getFormat() const { return UPX_F_VMLINUX_AMD64; }
|
||||
virtual const char *getName() const { return "vmlinux/AMD64"; }
|
||||
virtual const char *getFullName(const options_t *) const { return "amd64-linux.kernel.vmlinux"; }
|
||||
virtual const int *getCompressionMethods(int method, int level) const;
|
||||
virtual const int *getFilters() const;
|
||||
|
||||
protected:
|
||||
virtual void buildLoader(const Filter *ft);
|
||||
virtual void defineDecompressorSymbols();
|
||||
virtual Linker* newLinker() const;
|
||||
virtual bool is_valid_e_entry(Addr);
|
||||
virtual bool has_valid_vmlinux_head();
|
||||
virtual unsigned write_vmlinux_head(
|
||||
OutputFile *const fo,
|
||||
Shdr *const stxt
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user