`nm` output symbols not referenced by `LC_SYMTAB` - c

Why ?
I am trying to reproduce the behavior of nm.
Problem
The command nm /usr/libexec/sharingd output some stranges symbols like :
[..]
00000001001d7570 t -[_TtC8sharingd19SDAirDropHandlerIPA canHandleTransfer]
00000001001d8070 t -[_TtC8sharingd19SDAirDropHandlerIPA initWithTransfer:bundleIdentifier:]
00000001001d7ed0 t -[_TtC8sharingd19SDAirDropHandlerIPA singleItemActionTitle]
00000001001d75f0 t -[_TtC8sharingd19SDAirDropHandlerIPA suitableContentsDescription]
00000001001d7580 t -[_TtC8sharingd19SDAirDropHandlerIPA transferTypes]
00000001001e45a0 t -[_TtC8sharingd27SDAirDropContactHashManager .cxx_destruct]
00000001001daf60 t -[_TtC8sharingd27SDAirDropContactHashManager acquireTokenForIdentifier:]
00000001001dcf70 t -[_TtC8sharingd27SDAirDropContactHashManager init]
00000001001be700 t <redacted function 7904>
00000001001beb50 t <redacted function 7905>
00000001001bebf0 t <redacted function 7906>
00000001001bf050 t <redacted function 7907>
00000001001bf100 t <redacted function 7908>
00000001001bf3a0 t <redacted function 7909>
00000001001bf490 t <redacted function 7910>
00000001001bf4d0 t <redacted function 7911>
00000001001bf540 t <redacted function 7912>
00000001001bf580 t <redacted function 7913>
00000001001bf590 t <redacted function 7914>
00000001001bf5b0 t <redacted function 7915>
00000001001bf5d0 t <redacted function 7916>
00000001001bf5e0 t <redacted function 7917>
00000001001bf5f0 t <redacted function 7918>
[..]
My version of nm doesn't output these symbols.
Where do they come from ?
Ascertainments
1.
Part of those symbols name (i.e. _TtC8sharingd19SDAirDropHandlerIPA or canHandleTransfer) are present in the string table of the mach-o file.
However, they're present as different strings.
2.
The symbol <redacted function xxx> is not present anywhere in the mach-o file.
3.
Theses symbols are not references by the LC_SYMTABS load command.

I also reproduced the nm command and I also did not handle this case. Thank you for sharing.
Looking at the LLVM source code, it seems that:
if nm encounters a LC_FUNCTION_STARTS (function starts segment), then it will get different (function?) addresses.
It checks that each of theses addresses is already in the symbol table.
If it is not, then comes the case that we do not handle:
See the comment at line 1672: "See this address is not already in the table symbol fake up an nlist for it."
// See this address is not already in the symbol table fake up an
// nlist for it.
if (!found) {
NMSymbol F = {};
F.Name = "<redacted function X>";
F.Address = FoundFns[f] + BaseSegmentAddress;
F.Size = 0;
// There is no symbol in the nlist symbol table for this so we set
// Sym effectivly to null and the rest of code in here must test for
// it and not do things like Sym.getFlags() for it.
F.Sym = BasicSymbolRef();
F.SymFlags = 0;
F.NType = MachO::N_SECT;
F.NSect = 0;
StringRef SegmentName = StringRef();
StringRef SectionName = StringRef();
for (const SectionRef &Section : MachO->sections()) {
Section.getName(SectionName);
SegmentName = MachO->getSectionFinalSegmentName(
Section.getRawDataRefImpl());
F.NSect++;
if (F.Address >= Section.getAddress() &&
F.Address < Section.getAddress() + Section.getSize()) {
F.Section = Section;
break;
}
}
if (SegmentName == "__TEXT" && SectionName == "__text")
F.TypeChar = 't';
else if (SegmentName == "__DATA" && SectionName == "__data")
F.TypeChar = 'd';
else if (SegmentName == "__DATA" && SectionName == "__bss")
F.TypeChar = 'b';
else
F.TypeChar = 's';
F.NDesc = 0;
F.IndirectName = StringRef();
SymbolList.push_back(F);
if (FoundFns[f] == lc_main_offset)
FOS << "<redacted LC_MAIN>";
else
FOS << "<redacted function " << f << ">";
FOS << '\0';
FunctionStartsAdded++;
}
And that's how these symbols seem to appear.

Related

Solidity function with arrays gives overflow error

I have the same code without an array and it just works.
But In this one if i enter amount anything more than 0.001 ether it gives an overflow error.
I tried Other functions called in this one with errored values and they don't give an error.
CheckPairValue() and CheckSellPrice() works.
Code is to check my Wallet's worth in pancakeswap
Idk what's wrong.
Any help is appretiated.
Also Contract is verified on bscscan.
Contract
function GetSellValue(address[] memory TokenAddress, uint[] memory Amount)public view returns(uint256[] memory){
uint[] memory Value = new uint[](TokenAddress.length);
for(uint i = 0; i < TokenAddress.length; i++){
address Pair = CheckPairValue(TokenAddress[i], Amount[i] * 2);
address[] memory path;
if(Pair != PairAddresses[0]){
path = new address[](3);
path[0] = TokenAddress[i];
path[1] = Pair;
path[2] = PairAddresses[0];
}
else
{
path = new address[](2);
path[0] = TokenAddress[i];
path[1] = PairAddresses[0];
}
Value[i] = CheckSellPrice(Amount[i],path);
}
return Value;
}
0.001 ether input works , anything higher doesn't
I still don't know why remix errored like this.
But i've written a js code to call the contract and it works.

Octave - How can I use pararrayfun with a file in input?

I am a new Octave user. My Octave version is 4.4.1.
I need help on how to use the parallel package.
I have a function modele_file that takes in as input a class structure that contains the path to files. I have to load that 'mat' files (see the code below).
The problem is that octave indicates that my entry is not defined.
I would be grateful if someone can help me find what is missing in my code
files = dir('./../data/*.mat');
[row col] = size(files);
for k = 1:1000
name{k} = getfield(files, {k,1}, 'name');
end
fun_str = #(stg) strcat("./../data/", stg) ;
vec_name = arrayfun(fun_str, name) ;
vec_result = arrayfun(fun_str, repmat({"result/"}, row,1)) ;
a = [vec_name, vec_result'] ;
struct_info = cell2struct(a, {"name", "result"}, 1);
solution = pararrayfun(nproc, modele_file, struct_info)
Here an example of my function :
function modele = modele_file(info_struct)
file = info_struct{1} ;
path = info_struct{2} ;
load(strcat(file)) ;
modele.X = zeros(2,2) ;
save('file.mat', 'modele') ;
Although my function is able to work. My priority is to launch my function, I do not specifically need it to register in an object.
Thank you.

When i running the multiple execute statement service i got the error "Cannot read property "parameters" from null "

I want to insert the below default values when i am running the service i got this below error any one please tell me how to resolve.
Runtime error in script ("Process: 'CustomPersonalGS Practice' ProcessItem: 'Initialize' Type: 'ITEM'" -1:-1).TypeError: Cannot read property "parameters" from null
//Initialise SQL Query List
tw.local.sqlQueries = new tw.object.listOf.SQLStatement();
tw.local.sql = "";
tw.local.customerPD = new tw.object.customerPD1BO();
tw.local.customerPD.customerPersonalDetailsList = new tw.object.listOf.customerSpecificPersonalDetailsListBO();
var custPersonalDetails = new tw.object.customerSpecificPersonalDetailsListBO();
custPersonalDetails.customerId = "8467";
custPersonalDetails.custPersonalDetailsId = "8";
custPersonalDetails.isBPMEnabled = true;
custPersonalDetails.isCCPEnabled = true;
custPersonalDetails.isCCPMandatory = true;
custPersonalDetails.isLatestVersion = true
tw.local.customerPD.customerPersonalDetailsList.insertIntoList(tw.local.customerPD.customerPersonalDetailsList.listLength, custPersonalDetails);
tw.local.sql = "INSERT INTO CUSTOMPERSONALDETAILSQUESTION(CUSTOMERID,CUSTPERSONLADETAILSID,ISBPMENABLED,ISCCPENABLED,ISCCPMANDATORY,ISLATESTVERSION) VALUES (?,?,?,?,?,?) ";
function addSQLStatement() {
tw.local.sqlQueries[tw.local.sqlQueries.listLength] = new tw.object.SQLStatement();
}
function addParam(value,type,mode) {
log.info("VALUE :" + value);
var newParam = new tw.object.SQLParameter();
newParam.value = value;
newParam.type = type;
newParam.mode = mode;
if( tw.local.sqlQueries == null){
tw.local.sqlQueries = new tw.object.listOf.SQLStatement();
}
if( tw.local.sqlQueries[tw.local.sqlQueries.listLength] == null ){
tw.local.sqlQueries.insertIntoList(tw.local.sqlQueries.listLength, new tw.object.SQLStatement());
}
if(tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters == null ){
tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters = new tw.object.listOf.SQLParameter();
}
var paramsLength = tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters.listLength;
tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters[paramsLength] = newParam;
}
for(var i=0;i<tw.local.customerPD.customerPersonalDetailsList.listLength;i++){
addSQLStatement(tw.local.sql);
addParam(tw.local.customerPD.customerPersonalDetailsList[i].customerId,"VARCHAR","IN");
addParam(tw.local.customerPD.customerPersonalDetailsList[i].custPersonalDetailsId,"VARCHAR","IN");
var yesNoFlag = "N";
if(tw.local.customerPD.customerPersonalDetailsList[i].isBPMEnabled){
yesNoFlag="Y";
addParam(yesNoFlag,"CHAR","IN");
}
yesNoFlag = "N";
if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPEnabled){
yesNoFlag="Y";
addParam(yesNoFlag,"CHAR","IN");
}
yesNoFlag = "N";
if(tw.local.customerPD.customerPersonalDetailsList[i].isCCPMandatory){
yesNoFlag="Y";
addParam(yesNoFlag,"CHAR","IN");
}
yesNoFlag = "N";
if(tw.local.customerPD.customerPersonalDetailsList[i].isLatestVersion){
yesNoFlag="Y";
addParam(yesNoFlag,"CHAR","IN");
}
}
You didn't initialize the parameter list in your SQL as far as I can tell. That is on line 38 you call -
var paramsLength = tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters.listLength;
However when you create the entry in the tw.local.sqlQueries, you didn't initialize the parameter array. I'll also note that your addSQLStatement() function ignore the sql input (and that value is hard coded, so really you don't need to pass it in). I think if you change addSQLStatement to be something like -
function addSQLStatement(query) {
var targetQuery = new tw.object.SQLStatement();
targetQuery.sql = query;
tagetQuery.params = new tw.object.listOf.SQLParameter();
tw.local.sqlQueries[tw.local.sqlQueries.listLength] = targetQuery;
}
then your code will work. Additionally you could actually return targetQuery from this function and then pass it to the "addParams" method eliminating the need to find the last one in the array. Alternatively insert it in the beginning of the array instead and just update the 0th item instead of the last.
-AP
This comparison will never work properly. array[array.length] will always be null (line 35).
if (tw.local.sqlQueries[tw.local.sqlQueries.listLength].parameters == null ){
In addition, in the next lines, if you want to work with the last element of the list, you might want to use something like array[array.length - 1]. Personally, I'd use some temporary variable, do some stuff with it and insert it into the list at the end (similar to #Drux's answer).

Angular slugify leaving dash at the end

Remove accents and symbols slugify, but leaving dash at the end.
I would also share the same function between controllers , how do?
code:
$scope.slugify = function(slug){
str = slug.replace("-");
str = angular.lowercase(str);
str = str.replace(/[^A-Z0-9]+/ig, "-");
$scope.item.slug = str;
}
Example:
source: Neymar the best player!
return: neymar-the-best-player-
[Resolved]
i found this: https://github.com/paulsmith/angular-slugify
Main problem:
Remove accents and symbols slugify, but leaving dash at the end.
Before we go to the main problem, there are several parts of you code that needs mending.
The first replace() statement, works for dashes that between any other strings, but would definitely be a problem if dashes are placed in both ends of a string.
e.g. '-Some-Text-' results to 'undefinedSome-Textundefined'
To solve this problem you need to add the second argument for replace() with an empty string.
From:
str = slug.replace("-");
To:
str = slug.replace('-', '');
The second replace() statement has a regular expression flag representing, i, representing for a case-insensitive search. While your regular expression statement suggests an A-Z (uppercase expression), this in fact is redundant, since you've already modified the string into a lower case. So the statement should be changed:
From:
str = str.replace(/[^A-Z0-9]+/ig, "-");
To:
str = str.replace(/[^a-z0-9]+/g, "-");
Now for the main problem, you're simply missing a dash trimming function for both ends of the string.
Add this replace statement after the code in #2
str = str.replace(/^-+|-+$/g, '');
From what I see in your code, this seems to be more of a reusable function rather than something that can be attributed to a controller function. You can create a service for this specific function instead and inject it in your controller.
DEMO
.controller('SluggerController', function($scope, slugify) {
$scope.slug = 'Neymar the best player!';
$scope.item = { slug: '' };
$scope.slugify = function(slug) {
$scope.item.slug = slugify(slug);
};
})
.factory('slugify', function() {
return function(text) {
return angular.lowercase(text)
.replace('-', '')
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
};
});
UPDATE:
Since you don't want to include unicode characters as dashed characters then you can incorporate this with #2.
DEMO
Instead of:
str = str.replace(/[^a-z0-9]+/g, "-");
Change it to:
str = str.replace(/[^\u00BF-\u1FFF\u2C00-\uD7FF\w0-9]/g, '-');
As for how I got the regular expression, you can refer to this SO comment
To make it public there is a necessary step to return something. Then you can wrap it as a constant and inject in any controller.
app.controller('MainCtrl', function($scope, slugify) {
$scope.show = function(){
alert(slugify($scope.someText));
}
});
app.constant('slugify', function(slug){
str = slug.replace("-");
str = angular.lowercase(str);
str = str.replace(/[^A-Z0-9]+/ig, "-");
return str;
});
Also from the nature of the transformation applied by function it fits the pattern of filter.
app.filter('slugifyFilter', function(){
return function(slug){
str = slug.replace("-");
str = angular.lowercase(str);
str = str.replace(/[^A-Z0-9]+/ig, "-");
return str;
}
});
And use like this in template
{{someText | slugifyFilter}}
See it in action in plunker

How do I base58 encode a string?

char (* text)[1][45+1];
text = calloc(5000,(130+1));
strcpy(0[*text],"sometext)");
Now I want to encode "sometext" to base58, however, I do not know how, and oddly enough, there isn't one example of BASE58 in C.
The base58 encoding I'm interested in uses these symbols:
123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
It's been optimized to lessen the risk of mis-reading, so 0 and 'O' are both gone, for instance.
P.S
Don't mind the weird allocation and declaration of the variables, I was experimenting.
You're not supposed to encode strings, you're supposed to encode integers.
If starting with a string, you must first decide how to interpret it as an integer (might be base128, or something), then re-encode in base58.
Satoshi has the reference implementation (https://github.com/bitcoin/bitcoin/blob/master/src/base58.h)
However, he uses some utility bignum class to do it, and it's in C++. If you have access to a bignum library, you just keep dividing by 58 until the number is broken up. If you don't have a bignum library, AFAIK you're outta luck.
Here's an implementation in PHP for large numbers I've created for Amithings, beyond the integers (Integer -> http://php.net/manual/en/language.types.integer.php).
For example, try the example below (Don't forget to pass your ID to the function in string format. Use the PHP function strval()):
$number = '123456789009876543211234567890';
$result = base58_encode($number);
echo('Encoded: ' . $result . '<br>');
echo('Decoded: ' . base58_decode($result) . '<br>');
Important: You may consider to change this routine by including some sort of key/password/encryption to ensure that others can not decode your database IDs.
function base58_encode($input)
{
$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$base_count = strval(strlen($alphabet));
$encoded = '';
while (floatval($input) >= floatval($base_count))
{
$div = bcdiv($input, $base_count);
$mod = bcmod($input, $base_count);
$encoded = substr($alphabet, intval($mod), 1) . $encoded;
$input = $div;
}
if (floatval($input) > 0)
{
$encoded = substr($alphabet, intval($input), 1) . $encoded;
}
return($encoded);
}
function base58_decode($input)
{
$alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$base_count = strval(strlen($alphabet));
$decoded = strval(0);
$multi = strval(1);
while (strlen($input) > 0)
{
$digit = substr($input, strlen($input) - 1);
$decoded = bcadd($decoded, bcmul($multi, strval(strpos($alphabet, $digit))));
$multi = bcmul($multi, $base_count);
$input = substr($input, 0, strlen($input) - 1);
}
return($decoded);
}
My simple code with Crypto++ library:
string base58_encode(Integer num, string vers)
{
string alphabet[58] = {"1","2","3","4","5","6","7","8","9","A","B","C","D","E","F",
"G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c",
"d","e","f","g","h","i","j","k","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
int base_count = 58; string encoded; Integer div; Integer mod;
while (num >= base_count)
{
div = num / base_count; mod = (num - (base_count * div));
encoded = alphabet[ mod.ConvertToLong() ] + encoded; num = div;
}
encoded = vers + alphabet[ num.ConvertToLong() ] + encoded;
return encoded;
}
It's just for cryptocurrency wallets. string can be changed for other tasks.
Here is an implementation that seems to be pure c.
https://github.com/trezor/trezor-crypto/blob/master/base58.c

Resources