I'm trying to retrieve with Rust the unique identifier of the MSV authentication package. For that, i'm trying to use the Windows API function LsaLookupAuthenticationPackage, but it is returning the NTSTATUS constant 0xC00000FE (STATUS_NO_SUCH_PACKAGE), which acording to the official documentation it means "A specified authentication package is unknown".
To call LsaLookupAuthenticationPackage, I'm using the official crate to access the Windows API. Below I detail the activities that I perform before calling LsaLookupAuthenticationPackage:
1.- I run my code as System.
2.- I successfully enable SeTcbPrivilege using the function RtlAdjustPrivilege.
3.- I successfully call LsaRegisterLogonProcess to open a handle to start the interaction with the LSA.
4.- I use this handle to call LsaLookupAuthenticationPackage. Below, I show the code that I'm using to call LsaLookupAuthenticationPackage:
let package:[char;20]= ['M','S','V','1','_','0','_','P','A','C','K','A','G','E','_','N','A','M','E','\0'];
let auth_package: STRING = STRING {Length:19, MaximumLength:19, Buffer:transmute(package.as_ptr())};
let auth_package_ptr: *const STRING = transmute(&auth_package);
let auth_id: *mut u32 = transmute(&u32::default());
let ret = LsaLookupAuthenticationPackage(handle,auth_package_ptr,auth_id);
I also tried to use an &str instead of the char array to store the auth package name, but it didn't work either.
For me it's obvious that the function is working, so the problem seems to be that I'm not passing correctly the auth package name.
Related
In #solana/web3.js when you create a transaction instruction, you specify pubkeys of your accounts, program id, and just raw bytes of your "data" parameter. In anchor program you declare your module to be a program with corresponding attribute, and now your pub functions become instructions. I could not find in the anchor book, how specifically they serialize their instruction name. How do I specify for my JavaScript frontend which instruction do I want it to execute?
How do I specify for my JavaScript frontend which instruction I want it to execute?
Anchor uses IDL(Interface Description Language) for this purpose. whenever you complete your Solana program you can build it(anchor build). With this command, you have exported idl in root/target/idl folder. You can deploy this file to Solana network and fetch it and make a program in any client like ts(typescript) because of its mapping. You can open up one of the IDL.json files for better understanding. with this file, you can call instructions or use accounts of your Solana program.
Also, you have another file with ts extension inside root/target/types. We use this file inside anchor test for creating a program with that and also for specifying which instruction or account we want to use. Also, this file is useful for creating anchor programs inside clients. Because this file contains "export const IDL.....". So, we can use this file for creating program like this:
import { PROGRAM_ID } from "./constants";//program account public key
import { IDL } from "./your_directory_of_programs";// directory of copy/paste types/your_program.ts file
export function getProgramInstance(connection, wallet) {
if (!wallet.publicKey) return;
const provider = new anchor.AnchorProvider(
connection,
wallet,
anchor.AnchorProvider.defaultOptions()
);
// Read the generated IDL.
const idl = IDL;
// Address of the deployed program.
const programId = PROGRAM_ID;
// Generate the program client from IDL.
const program = new anchor.Program(idl, programId, provider);
return program;
}
and call any instruction like this:
await program.methods
.yourInstruction()
.accounts({
})
.signers()
.rpc();
Read this part of the Solana Cookbook for more details of what's going on when we want to call instruction of program from TS or any other clients.
I'm implementing server using GIN Framework.
The Gin framework has a handler for each route.
Each function handler has it's own controller that returns some result (basically error)
package controller
var (
ErrTooManyAttempts = errors.New("too many attempts")
ErrNoPermission = errors.New("no permission")
ErrNotAvailable = errors.New("not available")
)
This errors are created for developers and logging, so we need to beautify and translate these before sending them to the client.
To be able to get translation we should know the key of the message.
But the problem is I need to bind these errors in some map[error]string (key) to get translation key by error.
It's quite complex because I have to bind all the errors with the corresponding keys.
To improve it, I'd like to use reflection:
Get all variables in the package
Walk through and find Err prefix
Generate translation key based on package name and error name, ex: controller-ErrTooManyAttempts
Merge translation file, so it should look like this:
`
{
"controller-ErrTooManyAttempts": "Too many attempts. Please try again later",
"controller-ErrNoPermission": "Permission to perform this action is denied",
"controller-ErrNotAvailable": "Service not available. Please try again later"
}
`
What is the correct way to translate errors from the package? Is it possible to provide me with some example?
I have been trying to run the execute_sale ix from the mpl-auction-house package but I get this error in the logs I have got the sellInstruction and buyInstruction working
This is my Code
const executeSellInstructionAccounts:ExecuteSaleInstructionAccounts = {
buyer:buyerwallet.publicKey,
seller:Sellerwallet.publicKey,
tokenAccount:tokenAccountKey,
tokenMint:mint,
metadata:await getMetadata(mint),
treasuryMint:new anchor.web3.PublicKey(AuctionHouse.mint),
auctionHouse:new anchor.web3.PublicKey(AuctionHouse.address),
auctionHouseFeeAccount:new anchor.web3.PublicKey(AuctionHouse.feeAccount),
authority:new anchor.web3.PublicKey(AuctionHouse.authority),
programAsSigner:programAsSigner,
auctionHouseTreasury:new anchor.web3.PublicKey(AuctionHouse.treasuryAccount),
buyerReceiptTokenAccount:buyerATA.address,
sellerPaymentReceiptAccount:Sellerwallet.publicKey,
buyerTradeState:BuyertradeState,
escrowPaymentAccount:escrowPaymentAccount,
freeTradeState:freeTradeState,
sellerTradeState:SellertradeState,
}
const executeSellInstructionArgs:ExecuteSaleInstructionArgs = {
escrowPaymentBump:escrowBump,
freeTradeStateBump:freeTradeBump,
programAsSignerBump:programAsSignerBump,
buyerPrice:buyPriceAdjusted,
tokenSize:tokenSizeAdjusted,
}
const execute_sale_ix = createExecuteSaleInstruction(
executeSellInstructionAccounts,executeSellInstructionArgs
)
const execute_sale_tx = new anchor.web3.Transaction(
{
recentBlockhash: blockhash,
feePayer: Sellerwallet.publicKey,
}
)
execute_sale_tx.add(execute_sale_ix);
const execute_sale_res = await sprovider.sendAndConfirm(execute_sale_tx);
There is currently a discrepancy between the published AuctionHouse SDK and the underlying Rust program.
The console reference implementation is here: https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/cli/src/auction-house-cli.ts
The console reference implementation works because it loads the idl directly from the chain and is therefore up to date. It bypasses the AuctionHouse SDK completely.
However, if you're doing this in the browser, you probably don't want to load the IDL from the chain. You'd need things like a decompression library and that would blow up your package size quite a bit.
To work around this, I've forked metaplex repo here: https://github.com/neftworld/metaplex
The fork above has the following changes:
Including the IDL definition as a typescript src file (correct as at 30 May 2022)
Fetching auctionHouse program from local IDL definition instead getting it from the chain
Hence, you can use this as a base for your web implementation. To make this work on the web, you will need to remove references to keypair - console uses a key pair file - and use the browser wallet to sign the transaction before sending.
I've been working on cross contract calls and simulation testing. I gnereally have things working when I use function calls but I'm seeing a wasm execution error "HostError(ProhibitedInView { method_name: "promise_batch_create") when trying to use a 'view' to call a method that generates a cross contract call to get its information.
contract1 has a method (indirect_num_entries) that uses a cross contract call to a method (num_entries) in contract2 that returns acount (with no modifications)
const contract1 = new nearAPI.Contract(
account1, // the account object that is connecting
"example-contract.testnet",
{
// name of contract you're connecting to
viewMethods: ["indirect_num_entries"], // view methods do not change state but usually return a value
changeMethods: ["indirect_add_entry"], // change methods modify state
sender: account, // account object to initialize and sign transactions.
}
);
and for contract2
const contract2 = new nearAPI.Contract(
account2, // the account object that is connecting
"example-contract.testnet",
{
// name of contract you're connecting to
viewMethods: ["num_entries"], // view methods do not change state but usually return a value
changeMethods: ["add_entry"], // change methods modify state
sender: account, // account object to initialize and sign transactions.
}
);
All of that works correctly via the Javascript SDK for both adding and getting the number of entries.
However I ran into a problem while trying to create a simulation test and found that trying to use view on indirect_num_entries caused an error:
let x : u64 = view!(contract1.indirect_num_entries()).unwrap_json(); //error
caused the following runtime error:
An error occurred
Error: Querying [object Object] failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView { method_name: "promise_batch_create" })).
Playing around a bit I found that replacing the view! with a call! worked -- i.e.
let x : u64 = call!(root, contract1.indirect_num_entries()).unwrap_json(); // works
I also found that if I use the near-cli I see the same behavior i.e.
near call contract1 indirect_num_entries "{}" --accountI contract1 (works)
near view contract1 indirect_num_entries (errors)
whereas for views directly to the contract2 work just fine
near view contract2 num_entries (works)
let x : u64 = view!(contract2.num_entries()).unwrap_json(); // works
Is this as expected and view is only valid for methods that access (not modify) the local contract data and shouldn't be used for methods that issue a cross contract call? (Or am I doing something incorrectly?)
I can certainly imagine that there could be reasons for needing to use a call (e.g. perhaps the request for a cross contract call needs to be signed) but I don't recall anything/haven't found anything that seems to describes this. Is there a description or a explanation somewhere?
Thanks!
This article explains the issue
https://docs.near.org/docs/develop/contracts/as/intro#view-and-change-functions
view calls do not provide the same context as a change call
the reason is because view calls are unsigned. no sender has signed a transaction to make the call. this is useful, not requiring a signature, because some use cases are intended for casual browsing or frequent reading of data like browsing an NFT collection or rendering a dashboard
change calls require a signed transaction so they include context like sender and other details
cross-contract calls require gas and this gas should be charged to some account. without a signed transaction (in a view call) then there is no one to charge for this gas
this might make you wonder: "but don't view calls cost gas too?" ... yes, they do, and today the RPC node providers are subsidizing these calls but that may change in the future
I am using a 3rd party library that invokes a Core Foundation function.
Since that lib has a bug, passing incorrect values to a CF function, I need to intercept that call to fix the passed values.
How do I hook into the CF function call so that I can look at the passed parameters, change them and then call the actual (original) function?
I have the impression I can get to the actual function with the CFBundleGetFunctionPointerForName, passing CFBundleGetMainBundle()as the first parameter and the name of the CF function as the second parameter.
In my particular case, that would be:
void *p = CFBundleGetFunctionPointerForName (CFBundleGetMainBundle(), "CFRunLoopTimerCreate");
But that returns NULL.
I also tried this:
void *p = CFBundleGetFunctionPointerForName (CFBundleGetBundleWithIdentifier("com.apple.Cocoa"), "CFRunLoopTimerCreate");
That returns a non-null value but it still does not appear to be a pointer I could change but rather the actual starting address of the function's code.
So, how do I get an address of a function pointer to an imported API function that I can save and then change to point to my intercepting function? Or how else could I hook into an imported function?
CFBundleGetFunctionPointerForName will just return the address of a function in a given bundle; this will never let you change the destination of calls to the function. If you really want to do something like that, please refer to Is it possible to hook API calls on Mac OS? Note that this is highly not recommended.