Select the types of activity you want to include in your feed.
* CoreServices FileManager and DateTimeUtils work
* Split out Cocoa vars from libobjcdarwin
* Resolve binds in correct order
* Fix name translation use in dlsym()
* libc file attrlist dummy functions (cannot be supported)
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
2727-2828-2929-#include "leb.h"
3030-#include <stdint.h>
3131-3232-uint64_t uleb128(const uint8_t*& p)
3333-{
3434- uint64_t r = 0;
3535- int s = 0;
3636- do
3737- {
3838- r |= (uint64_t)(*p & 0x7f) << s;
3939- s += 7;
4040- }
4141- while (*p++ >= 0x80);
4242- return r;
4343-}
4444-4545-int64_t sleb128(const uint8_t*& p)
4646-{
4747- int64_t r = 0;
4848- int s = 0;
4949- for (;;) {
5050- uint8_t b = *p++;
5151- if (b < 0x80)
5252- {
5353- if (b & 0x40)
5454- r -= (0x80 - b) << s;
5555- else
5656- r |= (b & 0x3f) << s;
5757- break;
5858- }
5959- r |= (b & 0x7f) << s;
6060- s += 7;
6161- }
6262- return r;
6363-}
-39
src/libmach-o/leb.h
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
2727-2828-2929-#ifndef LEB_H
3030-#define LEB_H
3131-#include <stdint.h>
3232-3333-__attribute__ ((visibility ("default")))
3434-uint64_t uleb128(const uint8_t*& p);
3535-3636-__attribute__ ((visibility ("default")))
3737-int64_t sleb128(const uint8_t*& p);
3838-3939-#endif
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
2020+2121+#include "leb.h"
2222+#include <stdint.h>
2323+#include <stdexcept>
2424+2525+uint64_t uleb128(const uint8_t*& p)
2626+{
2727+ uint64_t r = 0;
2828+ int s = 0;
2929+ do
3030+ {
3131+ r |= (uint64_t)(*p & 0x7f) << s;
3232+ s += 7;
3333+ }
3434+ while (*p++ >= 0x80);
3535+ return r;
3636+}
3737+3838+int64_t sleb128(const uint8_t*& p)
3939+{
4040+ int64_t r = 0;
4141+ int s = 0;
4242+ for (;;)
4343+ {
4444+ uint8_t b = *p++;
4545+ if (b < 0x80)
4646+ {
4747+ if (b & 0x40)
4848+ r -= (0x80 - b) << s;
4949+ else
5050+ r |= (b & 0x3f) << s;
5151+ break;
5252+ }
5353+ r |= (b & 0x7f) << s;
5454+ s += 7;
5555+ }
5656+ return r;
5757+}
5858+5959+std::vector<uint8_t> uleb128(uint64_t v)
6060+{
6161+ if (!v)
6262+ return std::vector<uint8_t>({ 0 });
6363+6464+ std::vector<uint8_t> rv;
6565+ int bitsUsed = 0, bytesUsed;
6666+ for (int i = 0; i < 64; i++)
6767+ {
6868+ if (v & (1ll << i))
6969+ bitsUsed = i+1;
7070+ }
7171+7272+ // round it up to 7 bits
7373+ bytesUsed = (bitsUsed+6) / 7;
7474+7575+ for (int i = 0; i < bytesUsed; i++)
7676+ {
7777+ uint8_t enc = (v >> (i*7)) & 0x7f;
7878+ if (i+1 < bytesUsed)
7979+ enc |= 0x80;
8080+ rv.push_back(enc);
8181+ }
8282+8383+ return rv;
8484+}
8585+8686+8787+void LEBStream::add(uint64_t v)
8888+{
8989+ std::vector<uint8_t> enc = uleb128(v);
9090+ m_data.insert(m_data.end(), enc.begin(), enc.end());
9191+}
9292+9393+size_t LEBStream::count() const
9494+{
9595+ size_t count = 0;
9696+9797+ for (size_t i = 0; i < m_data.size(); i++)
9898+ {
9999+ if (!(m_data[i] & 0x80))
100100+ count++;
101101+ }
102102+103103+ return count;
104104+}
105105+106106+uint64_t LEBStream::pop()
107107+{
108108+ if (!bytes())
109109+ throw std::underflow_error("LEBStream::pop()");
110110+111111+ size_t start = 0;
112112+ for (size_t i = 0; i < m_data.size()-1; i++)
113113+ {
114114+ if (!(m_data[i] & 0x80))
115115+ start = i+1;
116116+ }
117117+118118+ const uint8_t* data = &m_data[start];
119119+ uint64_t v = uleb128(data);
120120+ m_data.resize(start);
121121+ return v;
122122+}
123123+124124+LEBStreamIterator LEBStream::begin() const
125125+{
126126+ return LEBStreamIterator(data(), 0, bytes());
127127+}
128128+129129+LEBStreamIterator LEBStream::end() const
130130+{
131131+ return LEBStreamIterator(data(), bytes(), bytes());
132132+}
133133+134134+LEBStreamIterator::LEBStreamIterator(const uint8_t* data, size_t bytes, size_t pos)
135135+: m_data(data), m_bytes(bytes), m_pos(pos)
136136+{
137137+}
138138+139139+uint64_t LEBStreamIterator::operator*()
140140+{
141141+ if (m_pos >= m_bytes)
142142+ return 0;
143143+144144+ const uint8_t* data = m_data + m_pos;
145145+ return uleb128(data);
146146+}
147147+148148+LEBStreamIterator& LEBStreamIterator::operator++(int)
149149+{
150150+ while (m_data[m_pos] & 0x80 && m_pos < m_bytes)
151151+ m_pos++;
152152+ return *this;
153153+}
154154+155155+bool LEBStreamIterator::operator!=(const LEBStreamIterator& that)
156156+{
157157+ return m_pos != that.m_pos;
158158+}
159159+
+71
src/util/leb.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
2020+2121+#ifndef LEB_H
2222+#define LEB_H
2323+#include <stdint.h>
2424+#include <vector>
2525+#include <stddef.h>
2626+2727+std::vector<uint8_t> uleb128(uint64_t v);
2828+uint64_t uleb128(const uint8_t*& p);
2929+3030+int64_t sleb128(const uint8_t*& p);
3131+3232+class LEBStreamIterator;
3333+3434+class LEBStream
3535+{
3636+public:
3737+ LEBStream();
3838+ void add(uint64_t v);
3939+4040+ // log(N)!
4141+ size_t count() const;
4242+4343+ // log(1)
4444+ inline size_t bytes() const { return m_data.size(); }
4545+ inline const uint8_t* data() const { return &m_data[0]; }
4646+4747+ // reverse of add()
4848+ uint64_t pop();
4949+5050+ LEBStreamIterator begin() const;
5151+ LEBStreamIterator end() const;
5252+private:
5353+ std::vector<uint8_t> m_data;
5454+};
5555+5656+class LEBStreamIterator
5757+{
5858+protected:
5959+ LEBStreamIterator(const uint8_t* data, size_t bytes, size_t pos = 0);
6060+public:
6161+ uint64_t operator*();
6262+ LEBStreamIterator& operator++(int);
6363+ bool operator!=(const LEBStreamIterator& that);
6464+private:
6565+ const uint8_t* m_data;
6666+ size_t m_bytes, m_pos;
6767+6868+ friend class LEBStream;
6969+};
7070+7171+#endif